<div>
    <x-title :breadcrumbs="[
        ['link' => route('wills-cases.index'), 'title' => 'Wills &amp; Trusts'],
        ['link' => '#', 'title' => 'New Case'],
    ]">
        New Wills &amp; Trusts Case
    </x-title>

    <div class="row justify-content-center">
        <div class="col-12 col-md-8">

            {{-- CLIENT DETAILS --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Client Details</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-2">
                            <x-ui.input name="title" label="Title" wire:model="title" placeholder="Mr / Mrs…"/>
                        </div>
                        <div class="col-12 col-md-4">
                            <x-ui.input name="name_first" label="First Name *" wire:model="name_first"/>
                            @error('name_first') <div class="text-danger small mt-1">{{ $message }}</div> @enderror
                        </div>
                        <div class="col-12 col-md-3">
                            <x-ui.input name="name_middle" label="Middle Name" wire:model="name_middle"/>
                        </div>
                        <div class="col-12 col-md-3">
                            <x-ui.input name="name_last" label="Last Name *" wire:model="name_last"/>
                            @error('name_last') <div class="text-danger small mt-1">{{ $message }}</div> @enderror
                        </div>
                        <div class="col-12 col-md-4">
                            <x-ui.input name="date_of_birth" label="Date of Birth" wire:model="date_of_birth" type="date"/>
                        </div>
                        <div class="col-12 col-md-4">
                            <x-ui.input name="phone_number" label="Phone Number" wire:model="phone_number"/>
                        </div>
                        <div class="col-12 col-md-4">
                            <x-ui.input name="email_address" label="Email Address" wire:model="email_address"/>
                        </div>
                    </div>
                </div>
            </div>

            {{-- CASE DETAILS --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Case Details</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-6">
                            <x-ui.input name="case_number" label="Case Number" wire:model="case_number"/>
                        </div>
                        <div class="col-12 col-md-6">
                            <x-ui.input name="national_insurance" label="National Insurance" wire:model="national_insurance"/>
                        </div>
                        <div class="col-12 col-md-6">
                            <x-ui.input name="fee_structure" label="Fee Structure" wire:model="fee_structure"/>
                        </div>
                        <div class="col-12 col-md-6">
                            <x-ui.input name="occupation" label="Occupation" wire:model="occupation"/>
                        </div>
                        <div class="col-12 col-md-4">
                            <label class="form-label">REP</label>
                            <select class="form-select" wire:model="rep">
                                <option value="">— Select —</option>
                                @foreach(\App\Models\WillsCase\WillsCase::REP_OPTIONS as $opt)
                                    <option value="{{ $opt }}">{{ $opt }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-12 col-md-4">
                            <label class="form-label">Case Owner</label>
                            <select class="form-select" wire:model="case_owner">
                                <option value="">— Select —</option>
                                @foreach(\App\Models\WillsCase\WillsCase::CASE_OWNER_OPTIONS as $opt)
                                    <option value="{{ $opt }}">{{ $opt }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-12 col-md-4">
                            <label class="form-label">Drafting Contact</label>
                            <select class="form-select" wire:model="drafting_contact">
                                <option value="">— Select —</option>
                                @foreach(\App\Models\WillsCase\WillsCase::DRAFTING_CONTACT_OPTIONS as $opt)
                                    <option value="{{ $opt }}">{{ $opt }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            {{-- PRODUCTS --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Products</h5>
                    <div class="row g-2">
                        @foreach(\App\Models\WillsCase\WillsCase::PRODUCT_OPTIONS as $idx => $opt)
                            <div class="col-12 col-md-6">
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input"
                                           value="{{ $opt }}"
                                           wire:model="products"
                                           id="product_{{ $idx }}">
                                    <label class="form-check-label" for="product_{{ $idx }}">{{ $opt }}</label>
                                </div>
                            </div>
                        @endforeach
                    </div>
                </div>
            </div>

            {{-- FINANCIAL --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Financial</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-6">
                            <x-ui.input name="our_fee" label="Our Fee" wire:model="our_fee"/>
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">AW&T Invoice Issued</label>
                            <input type="date" class="form-control" wire:model="awt_invoice_issued_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Our Fee Status</label>
                            <select class="form-select" wire:model="our_fee_status">
                                <option value="">— Select —</option>
                                @foreach(\App\Models\WillsCase\WillsCase::FEE_STATUS_OPTIONS as $opt)
                                    <option value="{{ $opt }}">{{ $opt }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-12 col-md-6">
                            <x-ui.input name="external_draft_fee" label="External Draft Fee" wire:model="external_draft_fee"/>
                        </div>
                    </div>
                </div>
            </div>

            {{-- WORKFLOW MILESTONES --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Workflow Milestones</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-6">
                            <label class="form-label">Welcome Letter Sent</label>
                            <input type="date" class="form-control" wire:model="welcome_letter_sent_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Introduction Call</label>
                            <input type="date" class="form-control" wire:model="introduction_call_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Intro Call By</label>
                            <select class="form-select" wire:model="intro_call_by">
                                <option value="">— Select —</option>
                                @foreach(\App\Models\WillsCase\WillsCase::INTRO_CALL_BY_OPTIONS as $opt)
                                    <option value="{{ $opt }}">{{ $opt }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Trust Docs Instructed</label>
                            <input type="date" class="form-control" wire:model="trust_docs_instructed_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">In House Instructed</label>
                            <input type="date" class="form-control" wire:model="in_house_instructed_at">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Docs Outstanding from Reps</label>
                            <textarea class="form-control" rows="2" wire:model="docs_outstanding_from_reps"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            {{-- DOCUMENT DRAFTING --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Document Drafting</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-6">
                            <label class="form-label">Drafts Received</label>
                            <input type="date" class="form-control" wire:model="drafts_received_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Drafts Issued to Client for Approval</label>
                            <input type="date" class="form-control" wire:model="drafts_issued_to_client_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Master Copies Signed by Client</label>
                            <input type="date" class="form-control" wire:model="master_copies_signed_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Master Copies Received in Office</label>
                            <input type="date" class="form-control" wire:model="master_copies_received_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Date on Document Signed</label>
                            <input type="date" class="form-control" wire:model="date_on_document_signed">
                        </div>
                    </div>
                </div>
            </div>

            {{-- REGISTRATION --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Registration</h5>
                    <div class="row g-3">
                        <div class="col-12">
                            <label class="form-label">Documents Requiring Registration</label>
                            <div class="d-flex gap-3">
                                <div class="form-check">
                                    <input type="radio" class="form-check-input" wire:model="documents_requiring_registration" value="1" id="drr_yes">
                                    <label class="form-check-label" for="drr_yes">Yes</label>
                                </div>
                                <div class="form-check">
                                    <input type="radio" class="form-check-input" wire:model="documents_requiring_registration" value="0" id="drr_no">
                                    <label class="form-check-label" for="drr_no">No</label>
                                </div>
                            </div>
                        </div>

                        <div class="col-12 col-md-6">
                            <label class="form-label fw-semibold">Documents to be Registered by Aiker</label>
                            @foreach(\App\Models\WillsCase\WillsCase::REGISTRATION_DOC_OPTIONS as $idx => $opt)
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input"
                                           value="{{ $opt }}"
                                           wire:model.live="documents_to_register_aiker"
                                           id="reg_aiker_{{ $idx }}">
                                    <label class="form-check-label" for="reg_aiker_{{ $idx }}">{{ $opt }}</label>
                                </div>
                            @endforeach
                        </div>

                        <div class="col-12 col-md-6">
                            <label class="form-label fw-semibold">Documents to be Registered by External</label>
                            @foreach(\App\Models\WillsCase\WillsCase::REGISTRATION_DOC_OPTIONS as $idx => $opt)
                                <div class="form-check">
                                    <input type="checkbox" class="form-check-input"
                                           value="{{ $opt }}"
                                           wire:model.live="documents_to_register_external"
                                           id="reg_ext_{{ $idx }}">
                                    <label class="form-check-label" for="reg_ext_{{ $idx }}">{{ $opt }}</label>
                                </div>
                            @endforeach
                        </div>

                        @if(count($documents_to_register_aiker))
                            <div class="col-12">
                                <label class="form-label fw-semibold">Registration Completed by Aiker</label>
                                <div class="row g-2">
                                    @foreach(\App\Models\WillsCase\WillsCase::REGISTRATION_DOC_OPTIONS as $idx => $opt)
                                        @if(in_array($opt, $documents_to_register_aiker))
                                            <div class="col-12 col-md-6">
                                                <label class="form-label small">{{ $opt }}</label>
                                                <input type="date" class="form-control form-control-sm"
                                                       wire:model="registration_completed_aiker.{{ $idx }}">
                                            </div>
                                        @endif
                                    @endforeach
                                </div>
                            </div>
                        @endif

                        @if(count($documents_to_register_external))
                            <div class="col-12">
                                <label class="form-label fw-semibold">Registration Completed by External</label>
                                <div class="row g-2">
                                    @foreach(\App\Models\WillsCase\WillsCase::REGISTRATION_DOC_OPTIONS as $idx => $opt)
                                        @if(in_array($opt, $documents_to_register_external))
                                            <div class="col-12 col-md-6">
                                                <label class="form-label small">{{ $opt }}</label>
                                                <input type="date" class="form-control form-control-sm"
                                                       wire:model="registration_completed_external.{{ $idx }}">
                                            </div>
                                        @endif
                                    @endforeach
                                </div>
                            </div>
                        @endif
                    </div>
                </div>
            </div>

            {{-- POST-COMPLETION --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Post-Completion</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-6">
                            <label class="form-label">Client Letters from HMRC Received</label>
                            <input type="date" class="form-control" wire:model="client_letters_from_hmrc_at">
                        </div>
                        <div class="col-12 col-md-6">
                            <label class="form-label">Annual Minutes Task Set</label>
                            <input type="date" class="form-control" wire:model="annual_minutes_task_set_at">
                        </div>
                    </div>
                </div>
            </div>

            {{-- DATES --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Dates</h5>
                    <div class="row g-3">
                        <div class="col-12 col-md-4">
                            <label class="form-label">Date/Time Opened</label>
                            <input type="date" class="form-control" wire:model="opened_at">
                        </div>
                        <div class="col-12 col-md-4">
                            <label class="form-label">Date/Time Closed</label>
                            <input type="date" class="form-control" wire:model="closed_at">
                        </div>
                        <div class="col-12 col-md-4">
                            <label class="form-label">IFA Referred Date</label>
                            <input type="date" class="form-control" wire:model="ifa_referred_date">
                        </div>
                    </div>
                </div>
            </div>

            {{-- FLAGS --}}
            <div class="card shadow-sm mb-4">
                <div class="card-body">
                    <h5 class="card-title mb-3">Flags</h5>
                    <div class="row g-3">
                        <div class="col-6 col-md-3">
                            <x-ui.checkbox name="is_open" label="Case is Open" wire:model="is_open"/>
                        </div>
                        <div class="col-6 col-md-3">
                            <x-ui.checkbox name="ifa_referred" label="IFA Referred" wire:model="ifa_referred"/>
                        </div>
                    </div>
                </div>
            </div>

            <div class="d-flex gap-2 mb-4">
                <x-ui.button wire:click="save" style="success" icon="mdi mdi-content-save">
                    Save Case
                </x-ui.button>
                <a href="{{ route('wills-cases.index') }}" class="btn btn-outline-secondary">Cancel</a>
            </div>

        </div>
    </div>
</div>
