@extends('setting.nav') @section('title', 'Lead Types') @section('content')

Lead Detection

The buying signals the classifier may detect in a mail, and how urgently each one is to be treated. These rows drive the AI prompt, the Lead and Priority columns on the mail list, the Leads filter menu and the dashboard card. The list is shared by everyone — a type an administrator adds here is detected on every user's mail, not just their own.

@if (session('success')) @endif @if (session('error')) @endif @if ($errors->any())
Please fix the following:
@endif @php $isAdmin = auth()->check() && auth()->user()->auth_id == 0; // Mail counts are keyed by the code stored on the row, and a type // also owns the words it lists as aliases. $countFor = function ($type) use ($counts) { $total = $counts[strtolower((string) $type->code)] ?? 0; foreach ($type->aliasList() as $alias) { $total += $counts[$alias] ?? 0; } return $total; }; @endphp @if ($usingDefaults) {{-- Nothing configured yet. The app is running on the built-in list, so say so plainly rather than showing an empty table. --}}
Running on the built-in lead types. The seven types below are already in force — they are what the AI is offered and what the mail list shows. Add them as rows to reorder them, reword them for your business, tune their score floors, or add your own.
@endif @if ($unclassified > 0) {{-- Every mail that arrived before this feature shipped. Worth stating, because those rows are inferred rather than detected. --}}
{{ number_format($unclassified) }} mails arrived before lead detection existed, so the AI never judged them. Those are treated as leads only where the old classifier already called them sales and they asked for a reply — marked inferred on the mail list, and carrying no score, because nothing scored them. Mail fetched from now on gets a real detection.
@endif
{{ $usingDefaults ? 'Lead types in force' : 'Lead types' }}
@if ($isAdmin && $canSeed)
@csrf
@endif
{{-- Floors, not widths. The Priority column made this the eighth in a card that is not eight columns wide, and without a minimum the browser reclaims the space from the two cells carrying sentences — which then wrap to six lines each. The wrapper scrolls sideways instead. --}} {{-- Counted across every mailbox, because deactivating a type affects every mailbox. The link opens your own listing. --}} @forelse ($types as $type) @empty {{-- No rows, so show the built-in list that is actually in force. --}} @foreach ($effective as $type) @endforeach @endforelse
Lead type AI code Floor Priority Mail (all users) Active Actions
{{ $loop->iteration }} {{ $type->name }} @if ($type->description)
{{ \Illuminate\Support\Str::limit($type->description, 120) }}
@endif @if ($type->ai_aliases)
also matches: {{ $type->ai_aliases }}
@endif
{{ $type->code }}
/mails/{{ $type->filter_slug }}
{{ (int) $type->min_score }} @php $band = $type->priorityBand(); $bandDef = $priorities[$band]; $fallsTo = \App\Models\LeadType::demote($band); @endphp {{ $bandDef['label'] }} @if ($fallsTo !== $band) {{-- The floor and the band interact, so the row says how, rather than leaving it to be worked out from two columns. --}}
under {{ \App\Models\LeadType::confidenceThresholdFor($type) }}: {{ strtolower($priorities[$fallsTo]['label']) }}
@endif
@php $used = $countFor($type); @endphp @if ($used > 0) {{ number_format($used) }} @else 0 @endif @if ($isAdmin)
@csrf
@else {{ $type->is_active ? 'Active' : 'Inactive' }} @endif
@if ($isAdmin) {{-- Order is the buying-signal ranking: the prompt prefers the type nearest the top when two of them fit. --}}
@csrf
@csrf
@csrf @method('DELETE')
@endif
{{ $loop->iteration }} {{ $type->name }} @if ($type->description)
{{ \Illuminate\Support\Str::limit($type->description, 120) }}
@endif
{{ $type->code }}
/mails/{{ $type->filter_slug }}
{{ (int) $type->min_score }} {{ $priorities[$type->priorityBand()]['label'] }} {{ number_format($countFor($type)) }} Built in not editable yet
@if ($isAdmin)
Add lead type
@csrf @include('lead_types._fields', ['type' => null, 'colours' => $colours, 'priorities' => $priorities])
@endif
{{-- Edit dialogs, one per row. --}} @if ($isAdmin) @foreach ($types as $type) @endforeach @endif
@endsection