<div>
    @if($client->claim()->exists())
        @php($claim = $client->claim)

        <div>
            <div class="card mb-3">
                <div class="card-body d-flex flex-column flex-md-row align-items-md-center justify-content-between gap-3">
                    <div>
                        <h5 class="card-title mb-1">Submit Application</h5>
                        <p class="text-muted mb-0">Send the application to the Scheme and a confirmation to the client.</p>
                    </div>

                    <div class="d-flex flex-column flex-md-row align-items-md-center gap-3">
                        @if($claim->app_sent_date)
                            <div class="text-md-end">
                                <span class="badge bg-success-subtle text-success">
                                    <i class="mdi mdi-check-circle-outline me-1"></i>Sent
                                </span>
                                <div class="small text-muted mt-1">{{ $claim->app_sent_date->format('d M Y') }}</div>
                            </div>
                        @endif

                        @can('communications.send.email')
                            <button type="button"
                                    class="btn btn-primary text-nowrap"
                                    wire:click="sendToRedress"
                                    wire:confirm="{{ $claim->app_sent_date ? 'Resend' : 'Send' }} the application to the Scheme and send confirmation to the client?"
                                    wire:loading.attr="disabled"
                                    wire:target="sendToRedress">
                                <span wire:loading.remove wire:target="sendToRedress">
                                    <i class="mdi mdi-send me-1"></i>{{ $claim->app_sent_date ? 'Resend' : 'Send' }} to Scheme &amp; Client
                                </span>
                                <span wire:loading wire:target="sendToRedress">Queuing...</span>
                            </button>
                        @endcan
                    </div>
                </div>
            </div>

            <!-- Horizontal Tabs -->
            <ul class="nav nav-tabs">
                @foreach($tabs as $key => $tab)
                    <li class="nav-item">
                        <button
                                wire:click="setTab('{{ $key }}')"
                                class="nav-link px-3 {{ $activeTab === $key ? 'active fw-bold text-primary' : 'text-muted' }}"
                                style="{{ $activeTab === $key ? 'border-top: 3px solid #0d6efd; background: white;' : '' }}"
                        >
                            <i class="bi {{ $tab['icon'] }} me-2"></i>
                            {{ $tab['label'] }}
                        </button>
                    </li>
                @endforeach
            </ul>

            @switch($activeTab)
                @case('personal-details')
                    <livewire:claim.application.personal-details :claim="$claim" wire:key="tab-personal-details"/>
                    @break

                @case('care-settings')
                    <livewire:claim.application.care-setting-manager :claim="$claim" wire:key="tab-care-settings"/>
                    @break

                @case('contact-preferences')
                    <livewire:claim.application.contact :client="$client" wire:key="tab-contact"/>
                    @break

                @case('confirm-identity')
                    <livewire:claim.application.confirm-identity :client="$client" wire:key="tab-confirm-identity"/>
                    @break

                @case('beneficiary')
                    <livewire:claim.application.beneficiary :claim="$claim" wire:key="tab-beneficiary"/>
                    @break

                @case('terminal-illness')
                    <livewire:claim.application.terminal-illness :claim="$claim" wire:key="tab-terminal"/>
                    @break

                @case('redress-type')
                    <livewire:claim.application.redress-type :claim="$claim" wire:key="tab-redress-type"/>
                    @break

                @case('bank-details')
                    <livewire:claim.application.bank-detail :claim="$claim" wire:key="tab-bank"/>
                    @break

                @case('impact-factors')
                    <livewire:claim.application.impact-factors :claim="$claim" wire:key="tab-impact"/>
                    @break

                @case('further-information')
                    <livewire:claim.application.further-information :claim="$claim" wire:key="tab-fi"/>
                    @break
                @case('provisional-value')
                    <livewire:claim.application.provisional-value :claim="$claim" wire:key="tab-provisional-value"/>
                    @break
            @endswitch
        </div>

    @else
        <div class="card border-0 shadow-sm">
            <div class="card-body">
                <h4 class="fw-bold mb-3 d-flex justify-content-between align-items-center">
                    Claim Info
                    @can('claims.create')
                    <a wire:navigate href="{{ route('claims.create', $client) }}" class="btn btn-sm btn-primary">
                        <i class="mdi mdi-plus"></i> Create Claim
                    </a>
                    @endcan
                </h4>
                <div class="text-center p-5 text-muted">
                    <i class="mdi mdi-account-details text-secondary opacity-25" style="font-size: 64px;"></i>
                    <p class="mt-3 fw-bold">No claim found for this client.</p>
                    <p class="small">Click the plus button above to start a new application.</p>
                </div>
            </div>
        </div>
    @endif
</div>
