{{-- Address Offcanvas - Right-side offcanvas form for add/edit address --}}
{{-- Props: $entityType, $entityId --}}
@php
    $addressTypes = [
        'billing' => __('Billing'),
        'shipping' => __('Shipping'),
        'office' => __('Office'),
        'warehouse' => __('Warehouse'),
        'home' => __('Home'),
        'other' => __('Other'),
    ];
@endphp

<div class="offcanvas offcanvas-end" tabindex="-1" id="addressOffcanvas" aria-labelledby="addressOffcanvasLabel">
    <div class="offcanvas-header">
        <h5 id="addressOffcanvasLabel" class="offcanvas-title">{{ __('Add Address') }}</h5>
        <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="{{ __('Close') }}"></button>
    </div>
    <div class="offcanvas-body mx-0 flex-grow-0">
        <form id="addressForm" onsubmit="return false;">
            @csrf
            <input type="hidden" name="_method" id="addressMethod" value="POST">
            <input type="hidden" name="address_id" id="address_id" value="">
            <input type="hidden" name="entity_type" value="{{ $entityType }}">
            <input type="hidden" name="entity_id" value="{{ $entityId }}">

            {{-- Address Type --}}
            <div class="mb-3">
                <label class="form-label" for="address_type">{{ __('Address Type') }} <span class="text-danger">*</span></label>
                <select id="address_type" name="address_type" class="form-select" required>
                    <option value="">{{ __('Select Type') }}</option>
                    @foreach($addressTypes as $value => $label)
                        <option value="{{ $value }}">{{ $label }}</option>
                    @endforeach
                </select>
                <div class="invalid-feedback"></div>
            </div>

            {{-- Address Line 1 --}}
            <div class="mb-3">
                <label class="form-label" for="address_line_1">{{ __('Address Line 1') }} <span class="text-danger">*</span></label>
                <input type="text" class="form-control" id="address_line_1" name="address_line_1" placeholder="{{ __('Street address, P.O. box') }}" required>
                <div class="invalid-feedback"></div>
            </div>

            {{-- Address Line 2 --}}
            <div class="mb-3">
                <label class="form-label" for="address_line_2">{{ __('Address Line 2') }}</label>
                <input type="text" class="form-control" id="address_line_2" name="address_line_2" placeholder="{{ __('Apartment, suite, unit, building, floor, etc.') }}">
                <div class="invalid-feedback"></div>
            </div>

            <div class="row">
                {{-- City --}}
                <div class="col-md-6 mb-3">
                    <label class="form-label" for="address_city">{{ __('City') }} <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="address_city" name="city" placeholder="{{ __('City') }}" required>
                    <div class="invalid-feedback"></div>
                </div>

                {{-- State --}}
                <div class="col-md-6 mb-3">
                    <label class="form-label" for="address_state">{{ __('State / Province') }}</label>
                    <input type="text" class="form-control" id="address_state" name="state" placeholder="{{ __('State / Province') }}">
                    <div class="invalid-feedback"></div>
                </div>
            </div>

            <div class="row">
                {{-- Postal Code --}}
                <div class="col-md-6 mb-3">
                    <label class="form-label" for="address_postal_code">{{ __('Postal Code') }}</label>
                    <input type="text" class="form-control" id="address_postal_code" name="postal_code" placeholder="{{ __('Postal Code') }}">
                    <div class="invalid-feedback"></div>
                </div>

                {{-- Country --}}
                <div class="col-md-6 mb-3">
                    <label class="form-label" for="address_country">{{ __('Country') }}</label>
                    <input type="text" class="form-control" id="address_country" name="country" placeholder="{{ __('Country') }}">
                    <div class="invalid-feedback"></div>
                </div>
            </div>

            {{-- Switches --}}
            <div class="row">
                {{-- Is Primary --}}
                <div class="col-md-4 mb-3">
                    <div class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" id="address_is_primary" name="is_primary" value="1">
                        <label class="form-check-label" for="address_is_primary">{{ __('Primary') }}</label>
                    </div>
                </div>

                {{-- Is Billing --}}
                <div class="col-md-4 mb-3">
                    <div class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" id="address_is_billing" name="is_billing" value="1">
                        <label class="form-check-label" for="address_is_billing">{{ __('Billing') }}</label>
                    </div>
                </div>

                {{-- Is Shipping --}}
                <div class="col-md-4 mb-3">
                    <div class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" id="address_is_shipping" name="is_shipping" value="1">
                        <label class="form-check-label" for="address_is_shipping">{{ __('Shipping') }}</label>
                    </div>
                </div>
            </div>

            {{-- General Error Message Area --}}
            <div class="mb-3">
                <small class="text-danger" id="address-general-error"></small>
            </div>

            {{-- Buttons --}}
            <div class="mt-4">
                <button type="submit" class="btn btn-primary me-sm-3 me-1" id="submitAddressBtn">
                    <i class="bx bx-save me-1"></i>{{ __('Save') }}
                </button>
                <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="offcanvas">
                    {{ __('Cancel') }}
                </button>
            </div>
        </form>
    </div>
</div>
