<section class="accordion accordion-flush ps-2" id="accordion-issuer">
    <div class="accordion-item">

        {{-- Title --}}
        <div class="accordion-header" id="issuer-unique-header">
            <button type="button" class="accordion-button fs-4 main-accordion-button ps-0 pe-3"
                data-bs-toggle="collapse" data-bs-target="#issuer-unique"
                aria-expanded="true" aria-controls="issuer-unique"
            >
                Emisor
            </button>
        </div>

        {{-- Content --}}
        <div id="issuer-unique"
            class="px-2 accordion-collapse collapse show row justify-content-start"
            aria-labelledby="issuer-unique-header"
        ><div class="px-2 accordion-body" id="issuer-form">

            {{-- Fiscal Data (Preloaded) --}}
            <div class="mb-3 row justify-content-start">

                {{-- Lugar de Expedición --}}
                <div class="flex-shrink-0 col-6">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="tax_branch_id" class="input-group-text">
                                Lugar de Expedición
                            </label>
                        </div>

                        <select id="tax_branch_id" name="tax_branch_id" class="form-control" required>
                            @foreach ($tax_branches as $txb)
                                <option value="{{ $txb->id }}">
                                    {{ $txb->legal_name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>

                {{-- Regimen Fiscal --}}
                @if ($is_mex_hotel)
                    <div class="flex-shrink-0 col-5">
                        <div class="mb-3 input-group">
                            <div class="input-group-prepend">
                                <label for="issuer_tax_system" class="input-group-text disabled-fields">
                                    {{ __('entity_fields')['common']['tax_system'] }}
                                </label>
                            </div>

                            @php
                                $establishment_tax_system = is_null( $establishment->tax_system )
                                    ? ""
                                    : $establishment->tax_system.' - '.\App\Helpers\Formats\TextTransformHelper::trimText($establishment->taxSystem->label, 35);
                            @endphp

                            <input type="text" id="issuer_tax_system" class="form-control disabled-fields" readonly
                                value="{{ $establishment_tax_system }}">
                        </div>
                    </div>
                @endif

            </div>

            {{-- CFDI Header --}}
            <div class="mb-3 row justify-content-start">

                {{-- Tipo de Comprobante --}}
                <div class="flex-shrink-0 col-4">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="invoice_type" class="input-group-text">
                                Tipo de Comprobante {!! $required_field !!}
                            </label>
                        </div>

                        <select id="invoice_type" name="invoice_type" class="form-control" required>
                            @foreach ($invoice_types as $it)
                                <option value="{{ $it->item_key }}" @if ($it->item_key === "I") selected @endif>
                                    {{ $it->item_key }} - {{ $it->label }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>

                {{-- Moneda --}}
                <div class="flex-shrink-0 col-4">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="currency" class="input-group-text">
                                Moneda {!! $required_field !!}
                            </label>
                        </div>

                        <select id="currency" name="currency" required
                            data-live-search="true" data-container="body"
                            data-dropup-auto="false" data-size="10"
                            class="selectpicker form-control dropup"
                        >
                            @foreach ($tax_currencies as $tc)
                                <option value="{{ $tc->item_key }}" @if ($tc->item_key === "MXN") selected @endif>
                                    {{ $tc->item_key }} - {{ $tc->label }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>

                {{-- Razón de Cambio (Solo con moneda extranjera) --}}
                <div class="flex-shrink-0 col-4" id="exchange_rate_block">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="exchange_rate" class="input-group-text">
                                Tipo de Cambio {!! $required_field !!}
                            </label>
                        </div>

                        <input type="number" id="exchange_rate" name="exchange_rate" required readonly
                            step="0.000001" min="0.000001" value="1.00" onchange="roundDecimals(this, 6)"
                            class="form-control disabled-fields" placeholder="$0.00">
                    </div>
                </div>

                {{-- Tipo de Exportación --}}
                <div class="flex-shrink-0 col-4">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="export" class="input-group-text">
                                Exportación {!! $required_field !!}
                            </label>
                        </div>

                        <select id="export" name="export" class="form-control" required>
                            @foreach ($exports as $export)
                                <option value="{{ $export->item_key }}">
                                    {{ $export->item_key }} - {{ $export->label }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>

                {{-- Método de Pago --}}
                <div class="flex-shrink-0 col-4">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="payment_method" class="input-group-text">
                                Método de Pago {!! $required_field !!}
                            </label>
                        </div>

                        <select id="payment_method" name="payment_method" class="form-control" required>
                            <option value="" selected disabled>-- {{ __('common_actions')['select'] }} --</option>

                            @foreach ($tax_payment_methods as $tpm)
                                <option value="{{ $tpm->item_key }}" @if($tpm->item_key === "PUE") selected @endif>
                                    {{ $tpm->item_key }} - {{ $tpm->label }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>

                {{-- Forma de Pago --}}
                <div class="flex-shrink-0 col-4">
                    <div class="mb-3 input-group" id="payment_form_group">
                        <div class="input-group-prepend">
                            <label for="payment_form" class="input-group-text">
                                Forma de Pago {!! $required_field !!}
                            </label>
                        </div>

                        <select id="payment_form" name="payment_form" class="form-control" required>
                            <option value="" disabled selected>{{ __('neutral_words')['none'] }}</option>

                            @foreach ($tax_payment_forms as $tpf)
                                <option value="{{ $tpf->item_key }}">
                                    {{ $tpf->item_key }} - {{ $tpf->label }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                </div>

            </div>

            {{-- Clarification Data --}}
            <div class="mb-3 row justify-content-start">

                @php
                    use Carbon\Carbon;
                    $default_due_date = Carbon::now()->addMonths(1);
                @endphp

                {{-- Días de Crédito --}}
                <div class="flex-shrink-0 col-4" id="credit_days_block">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="credit_days" class="input-group-text">
                                Días de crédito
                            </label>
                        </div>

                        <input type="number" id="credit_days" name="credit_days"
                            min="1" step="1" value="{{ $today->diffInDays($default_due_date) }}"
                            placeholder="{{ __('entity_forms')['tax_invoice']['placeholders']['credit_days'] }}"
                            onchange="roundInteger(this, null)" class="form-control">
                            {{-- onchange="roundInteger(this, 30)" class="form-control"> --}}
                    </div>
                </div>

                {{-- Limite de Pago --}}
                <div class="flex-shrink-0 col-4" id="due_date_block">
                    <div class="mb-3 input-group">
                        <div class="input-group-prepend">
                            <label for="due_date" class="input-group-text">
                                Fecha Limite de Pago
                            </label>
                        </div>

                        <input type="date" id="due_date" name="due_date" readonly
                            min="{{ $today->format('Y-m-d') }}" value="{{ $default_due_date->format('Y-m-d') }}"
                            class="form-control disabled-fields">
                    </div>
                </div>

                {{-- Notes --}}
                <div class="mb-4 input-group">
                    <label for="notes" class="input-group-text textarea-label">
                        Información Adicional / Especificaciones
                    </label>

                    @php
                        use App\Enums\Invoicing\BillableService;

                        $default_notes = __('neutral_words')['none'];


                        if ($service_id && $service_type) {
                            $label = BillableService::labelFrom($service_type);

                            if ($label)
                                $default_notes = $label . " #{$service_id}";
                        }
                    @endphp

                    <textarea id="notes" name="notes" rows="3" placeholder="...">{{ $default_notes }}</textarea>
                </div>

            </div>

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