<div>
    <x-title :breadcrumbs="[
        ['link' => route('clients.index'), 'title' => 'Clients'],
        ['link' => route('clients.show', $client), 'title' => $client->name_first . ' ' . $client->name_last],
    ]">
        View Client
    </x-title>

    @php
        $ageFlag      = $client->date_of_birth?->age >= 68;
        $terminalFlag = $client->claim?->terminalIllness !== null;
        $isHighPriority = $ageFlag || $terminalFlag;
    @endphp
    @if($isHighPriority)
        <div class="alert alert-danger d-flex align-items-center mb-3 shadow-sm border-0 border-start border-danger border-4"
             role="alert">
            <i class="mdi mdi-alert-octagon fs-2 me-3"></i>
            <div>
                <strong class="d-block">High Priority Client</strong>
                <span class="small">
                    @php
                        $reasons = [];
                        if ($ageFlag)      $reasons[] = 'client is ' . $client->date_of_birth->safeAge() . ' (68+)';
                        if ($terminalFlag) $reasons[] = 'terminal illness recorded';
                    @endphp
                    {{ ucfirst(implode(' and ', $reasons)) }}.
                </span>
            </div>
        </div>
    @endif

    <div class="row">

        <div class="col-12 col-md-3 position-relative">
            <div wire:loading.remove>
                <x-client.client-card :client="$client"/>
           
                <x-wip-summary-card
                    :units="$totalWipUnits"
                    :seconds="$totalWipSeconds"
                    :client="$client"
                />
            
                
                <livewire:client.edit-lead-source :client="$client"/>

                @isset($claim)
                    <livewire:claim.edit-status :claim="$claim"/>
                @endisset

                <div class="card">
                    <div class="card-body">
                        <h4 class="fw-bold">Funding Tranche</h4>
                        @if($client->tranche()->exists())
                            <p>{{ $client->tranche->funder_name }} - {{ $client->tranche->tranche_name }}</p>
                        @else
                            <p>No funding tranche assigned.</p>
                        @endif
                    </div>
                </div>
            </div>

        </div>

        <div class="col-12 col-md-6 position-relative">

            <div wire:loading.remove>
                <livewire:client.client-tabs :client="$client"/>
            </div>

        </div>
          
        <div class="col-12 col-md-3 position-relative">

            <div wire:loading.remove>
                <livewire:note-manager :owner="$client"/>
                <livewire:claim.institution-manager :claim="$client->claim"/>
            </div>

        </div>

    </div>
</div>
