{{-- Constants --}}
@php
    // Visual Support
    $required_field = "&nbsp;<span class='text-danger'>*</span>";
@endphp

{{--Styles--}}
<style>
    #tax_client_form label, #tax_client_form p {
        text-transform: uppercase;
    }

    .tax-text, .tax-text::placeholder{
        text-transform: uppercase;
    }
</style>

{{-- Modal --}}
<div id="taxClientFormModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="p-4 modal-body special-modal-body">

                {{-- Header --}}
                <div class="row justify-content-center align-items-baseline border-bottom">
                    {{-- Title --}}
                    <div class="pt-1 text-center col-11">
                        <h4 class="modal_title"></h4>
                        <h6 class="modal_subtitle"></h6>
                    </div>

                    {{-- Close Button --}}
                    <div class="pt-1 text-center col-1">
                        <button type="button" class="mt-0 close" data-dismiss="modal" style="float: none; font-size: 2.3rem;">&times;</button>
                    </div>
                </div>

                {{-- Form --}}
                <form method="post" id="tax_client_form"
                    class="px-3 py-4 form-horizontal" enctype="multipart/form-data"
                >@csrf

                    {{-- Fiscal Data --}}
                    <section class="mb-3">
                        {{-- Subtitle --}}
                        <p class="mb-3 border-bottom fw-semi-bold">
                            {{ __('entity_forms')['tax_prod_serv']['sections']['fiscal_data'] }}
                        </p>

                        {{-- Content --}}

                        <div class="row">
                            {{-- Is Moral --}}
                            <div class="px-2 form-group col-12">
                                <div class="mb-2 d-flex align-self-center ps-2">
                                    <p class="text-center text-uppercase minus-title fw-semi-bold">
                                        Tipo de Persona:
                                    </p>
                                    <label for="client_is_moral" class="mx-3 switch switch_label">
                                        <input type="checkbox" id="client_is_moral" name="client_is_moral">
                                        <span class="specific_slider slider round"></span>
                                    </label>
                                    <p class="text-center text-uppercase fw-semi-bold" id="person_type">Física</p>
                                </div>
                            </div>

                            {{-- Legal Name --}}
                            <div class="px-2 col-md-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_legal_name" class="input-group-text">
                                            {{ __('entity_fields')['common']['legal_name'] }} {!! $required_field !!}
                                        </label>
                                    </div>
                                    <input type="text" id="client_legal_name" name="client_legal_name" required
                                        class="form-control tax-text" placeholder="{{ __('entity_fields')['common']['legal_name'] }}">
                                </div>
                            </div>

                            {{-- Tax Id (RFC) --}}
                            <div class="px-2 col-md-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_id" class="input-group-text">
                                            {{ __('entity_fields')['establishment']['tax_id'] }} {!! $required_field !!}
                                        </label>
                                    </div>
                                    <input type="text" id="client_tax_id" name="client_tax_id"
                                        class="form-control tax-text" placeholder="{{ __('entity_fields')['establishment']['tax_id']}}">
                                </div>
                            </div>

                            {{-- Tax System (Regimen Fiscal)--}}
                            @if ($is_mex_hotel)
                                <div class="px-2 col-md-4">
                                    <div class="mb-3 input-group">
                                        <div class="input-group-prepend">
                                            <label for="client_tax_system" class="input-group-text">
                                                {{ __('entity_fields')['common']['tax_system'] }}  {!! $required_field !!}
                                            </label>
                                        </div>
                                        <select id="client_tax_system" name="client_tax_system" class="form-control" required></select>
                                    </div>
                                </div>
                            @endif

                            {{-- CFDI Use --}}
                            <div class="px-2 col-md-5">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_cfdi_use" class="input-group-text">
                                            Uso del CFDI {!! $required_field !!}
                                        </label>
                                    </div>

                                    <select id="client_cfdi_use" name="client_cfdi_use" class="form-control" required></select>
                                </div>
                            </div>

                        </div>
                    </section>

                    {{--Contact Data--}}
                    <section class="mb-3">
                        {{--Subtitle--}}
                        <p class="mb-3 border-bottom fw-semi-bold">
                            Contacto
                        </p>

                        {{--Content--}}
                        <div class="row">

                            {{-- Email Billing --}}
                            <div class="px-2 form-group row col-md-6 justify-content-center">
                                <label for="client_email_billing" class="text-center col-md-3" style="padding-top: 0.5rem !important;">
                                    {{ __('entity_fields')['common']['email'] }} {!! $required_field !!}
                                </label>

                                <div class="col-md-9">
                                    <input type="email" id="client_email_billing" name="client_email_billing"
                                        class="form-control" placeholder="ejemplo@gmail.com">
                                </div>
                            </div>

                            {{--Client Phone--}}
                            <div class="px-2 form-group row col-md-6 justify-content-center">
                                <label for="client_phone" class="text-center col-md-3" style="padding-top: 0.5rem !important;">
                                    {{ __('entity_fields')['common']['phone']}}
                                </label>

                                <div class="col-md-9">
                                    <input type="tel" id="client_phone" name="client_phone"
                                    class="form-control" placeholder="+() 000-000-0000">
                                </div>
                            </div>

                        </div>
                    </section>


                    {{-- Tax address--}}
                    <section class="mb-3">
                        {{-- Subtitle --}}
                        <p class="mb-3 border-bottom fw-semi-bold">
                            {{ Str::upper(__('entity_fields')['establishment']['address']) }}
                        </p>

                        {{-- Content --}}
                        <div class="row">

                            {{-- Zip (Postal Code)  --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_zip" class="input-group-text">
                                            {{ __('entity_fields')['common']['zip_compact'] }}  {!! $required_field !!}
                                        </label>
                                    </div>

                                    <input type="text" name="client_zip" id="client_zip" required
                                        autocomplete="off" class="form-control tax-text" placeholder=" {{ __('entity_fields')['common']['zip'] }}"/>
                                </div>
                            </div>

                            {{-- Street --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_street" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['street'] }}
                                        </label>
                                    </div>

                                    <input type="text" name="client_tax_address_street" id="client_tax_address_street"
                                        pattern="^[A-Za-zÀ-ÿÑñ0-9 .,'#\-\/]{2,80}$"
                                        title="{{ __('entity_forms')['pattern_titles']['address']['street'] }}"
                                        minlength="2" maxlength="80" autocomplete="off"
                                        class="form-control tax-text" placeholder="{{ __('entity_fields')['common']['tax_address']['street'] }} ..."/>
                                </div>
                            </div>

                            {{-- Internal Number --}}
                            <div class="px-2 col-2">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_interior" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['int_number'] }}
                                        </label>
                                    </div>

                                    <input type="text" name="client_tax_address_interior" id="client_tax_address_interior"
                                        maxlength="50" pattern="^(S\/N|SN|s\/n|sn|[A-Za-z0-9\-\/# ]{1,50})$"
                                        title="{{ __('entity_forms')['pattern_titles']['address']['int_number'] }}"
                                        class="form-control tax-text" autocomplete="off" placeholder="00"/>
                                </div>
                            </div>

                            {{-- External Number --}}
                            <div class="px-2 col-2">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_exterior" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['ext_number'] }}
                                        </label>
                                    </div>

                                    <input type="text" name="client_tax_address_exterior" id="client_tax_address_exterior"
                                        maxlength="50" pattern="^(S\/N|SN|s\/n|sn|[A-Za-z0-9\-\/# ]{1,50})$"
                                        title="{{ __('entity_forms')['pattern_titles']['address']['ext_number'] }}"
                                        class="form-control tax-text" autocomplete="off" placeholder="00"/>
                                </div>
                            </div>

                            {{-- Neighborhood --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_neighborhood" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['neighborhood'] }}
                                        </label>
                                    </div>

                                    <select name="client_tax_address_neighborhood" id="client_tax_address_neighborhood"
                                        class="selectpicker form-control" data-live-search="true"
                                        title="{{ mb_strtoupper(__('entity_fields')['common']['tax_address']['neighborhood'])  }} ...">
                                    </select>
                                </div>
                            </div>

                            {{-- City --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_city" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['city'] }}
                                        </label>
                                    </div>

                                    <input type="text" name="client_tax_address_city" id="client_tax_address_city"
                                        class="form-control tax-text" autocomplete="off"
                                        placeholder="{{ __('entity_fields')['common']['tax_address']['city'] }} ..."/>
                                </div>
                            </div>

                            {{-- Municipality --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_municipality" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['municipality'] }}
                                        </label>
                                    </div>

                                    <input type="text" name="client_tax_address_municipality" id="client_tax_address_municipality"
                                        minlength="2" maxlength="60" autocomplete="off"
                                        pattern="^[A-Za-zÀ-ÿÑñ .,'\-]{2,60}$" class="form-control tax-text"
                                        title="{{ __('entity_forms')['pattern_titles']['address']['municipality'] }}"
                                        placeholder="{{ __('entity_fields')['common']['tax_address']['municipality'] }} ..."/>
                                </div>
                            </div>

                            {{-- State --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend">
                                        <label for="client_tax_address_state" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['state'] }}
                                        </label>
                                    </div>

                                    <input type="text" name="client_tax_address_state" id="client_tax_address_state"
                                        minlength="2" maxlength="60" autocomplete="off"
                                        pattern="^[A-Za-zÀ-ÿÑñ .,'\-]{2,60}$" list="tax-client-mx-states"
                                        title="{{ __('entity_forms')['pattern_titles']['address']['state'] }}"
                                        class="form-control tax-text" placeholder="{{ __('entity_fields')['common']['tax_address']['state'] }} ..."/>

                                    <datalist id="tax-client-mx-states"></datalist>
                                </div>
                            </div>

                            {{-- Country --}}
                            <div class="px-2 col-4">
                                <div class="mb-3 input-group">
                                    <div class="input-group-prepend" >
                                        <label for="client_tax_address_country" class="input-group-text">
                                            {{ __('entity_fields')['common']['tax_address']['country'] }}
                                        </label>
                                    </div>

                                    <select name="client_tax_address_country" id="client_tax_address_country"
                                        class="selectpicker form-control"
                                        data-live-search="true"
                                        title="{{ __('common_actions')['select'] }}..."
                                        >
                                        @foreach ($country_sets as $c_code)
                                            <option value="{{ $c_code }}">{{ mb_strtoupper(__("countries.$c_code")) }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                        </div>
                    </section>

                    {{-- Buttons --}}
                    <div class="form-group" align="center">
                        <input type="hidden" name="action" id="action"/>
                        <input type="hidden" name="hidden_id" id="hidden_id"/>

                        <input type="submit" name="action_button" id="action_button" class="p-1 btn boton"
                            value="{{ __('common_actions')['add'] }}" />
                    </div>
                </form>

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

{{-- Scripts --}}

{{-- Format Controls --}}
<script src="{{ asset('js/invoicing/tax-formats.js') }}"></script>

<script>
  //* CRUD Control
    $(document).ready(function () {
        //Variable para controlar la limpieza del formulario atomatico
        let is_editing_record = false;

        //- Initial Loading
        defineMoralTaxIdFormat("client_tax_id");
        defineMoralTaxSystems("client_tax_system");
        defineMoralCfdiUses("client_cfdi_use");

        definePostalCodeFormat("client_zip");
        defineOptionalStates();
        restoreTaxClientForm();

        // On change important texts
        $('#tax_client_form').on('input', 'input[type="text"], textarea',function(){
            $(this).val($(this).val().toUpperCase());
        });

        //- On close Receiver form
        $('#taxClientFormModal').on('hide.bs.modal', function () {
            document.activeElement.blur();
        });

        // Open For Create
        $('#create_record').click(function () {
          // Control Variables
            is_editing_record = false;

          // Restore Form
            // Fields
            restoreTaxClientForm();

            // Titles
            $('.modal_title').text("{{ __('entity_forms')['common']['modal_title'] }}");
            $('.modal_subtitle').text("- {{ __('entities')['hotel']['client'] }} -");

            // Actions
            $('#action_button').val("{{ __('common_actions')['add'] }}");
            $('#action').val("Add");

            // Show modal
            $('#taxClientFormModal').modal('show');
        });

        // Open For Edit
        $(document).on('click', '.edit', function () {
            is_editing_record = true;
            var id = $(this).attr('id');

            $.ajax({
                url: `/invoicing/clients/${id}/edit`,
                dataType: "json",
                success: async function (html) {
                  // Parse Data
                    const data = html.data;

                  // Reset Form
                    restoreTaxClientForm();

                  // Seed inputs
                    $('#hidden_id').val(data.id);
                    $('#client_legal_name').val(data.legal_name);
                    $('#client_is_moral').prop('checked',data.is_moral).trigger('change');
                    $('#client_tax_system').val(data.tax_system);
                    $('#client_tax_id').val(data.tax_id);
                    $('#client_cfdi_use').val(data.cfdi_use);
                    $('#client_email_billing').val(data.email_billing);
                    $('#client_phone').val(data.client_phone);
                    $('#client_zip').val(data.zip);

                  // Tax Address
                    $('#client_tax_address_street').val(data.tax_address.street);
                    $('#client_tax_address_exterior').val(data.tax_address.exterior);
                    $('#client_tax_address_interior').val(data.tax_address.interior);
                    $('#client_tax_address_city').val(data.tax_address.city);
                    $('#client_tax_address_municipality').val(data.tax_address.municipality);
                    $('#client_tax_address_state').val(data.tax_address.state);
                    $('#client_tax_address_country').val(data.tax_address.country);

                  // Neighborhood Case
                    try{
                        await loadNeighborhoodsFromPostaliaOrFail(
                            data.zip,
                            data.tax_address?.neighborhood,
                            $('#client_tax_address_neighborhood')
                        );
                    } catch(error){
                        console.error(error.message);
                    }

                  // UPdate Modal
                    $('.modal_title').text("{{ __('entity_forms')['common']['modal_title_2'] }}");
                    $('.modal_subtitle').text(`${data.tax_id}`);
                    $('#action_button').val("{{ __('common_actions')['update'] }}");
                    $('#action').val("Edit");

                  // Show Modals
                    $('#taxClientFormModal').modal('show');
                }
            });
        });

        // Open For Delete
        $(document).on('click', '.delete', function () {
            var id = $(this).attr('id');
            Swal.fire({
                type: 'warning',
                title: "{{ __('common_responses_and_messages')['confirm_deletion'] }}",
                confirmButtonText: "{{ __('common_actions')['approve'] }} {{ __('common_actions')['confirm_deletion'] }}",
                confirmButtonColor: `#0d6889`,
                showCancelButton: true,
                cancelButtonText: `{{ __('common_actions')['cancel'] }}`,
                cancelButtonColor: `#c82333`
            }).then((result) => {
                /* Read more about isConfirmed, isDenied below */
                if (result.value) {
                    $.ajax({
                        url: `/clients/${id}/destroy`,
                        success: function (data) {
                            setTimeout(function () {
                                Swal.fire(
                                    "{{ __('common_responses_and_messages')['deleted'] }}",
                                    "{{ __('common_responses_and_messages')['deleted_successfully'] }}",
                                    'success'
                                );
                                $('#tax_clients_table').DataTable().ajax.reload(null, false);
                            }, 200);
                        },

                        error: function (error) {
                            Swal.fire(
                                "{{ __('common_responses_and_messages')['rejected_action'] }}",
                                error.responseJSON.message,
                                'error'
                            );
                        }
                    });
                }
            });
        });

        // Submit Form
        $('#tax_client_form').on('submit', function (event) {
            event.preventDefault();

            const data = {
                tax_identifier: $('#client_tax_id').val(),
                is_moral_person: $('#client_is_moral').is(':checked') ? 1 : 0,
                legal_name: $('#client_legal_name').val(),
                tax_system: $('#client_tax_system').val(),
                cfdi_use: $('#client_cfdi_use').val(),
                email_billing: $('#client_email_billing').val(),
                phone_billing: $('#client_phone').val(),
                individual_zip: $('#client_zip').val(),

                individual_street: $('#client_tax_address_street').val(),
                individual_ext_number: $('#client_tax_address_exterior').val(),
                individual_int_number: $('#client_tax_address_interior').val(),
                individual_neighborhood: $('#client_tax_address_neighborhood').val(),
                individual_city: $('#client_tax_address_city').val(),
                individual_municipality: $('#client_tax_address_municipality').val(),
                individual_state: $('#client_tax_address_state').val(),
                individual_country: $('#client_tax_address_country').val(),
            }


            if ($('#action').val() == 'Add') {
                $.ajax({
                    headers:{
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    url: "{{ route('tax-clients.store') }}",
                    method: "POST",
                    data: data,
                    success: function (data) {
                        if (data.success) {
                            Swal.fire(
                                "{{ __('common_responses_and_messages')['success'] }}",
                                "{{ __('common_responses_and_messages')['created_successfully'] }}",
                                'success'
                            );
                            $('#tax_client_form')[0].reset();
                            $('#tax_clients_table').DataTable().ajax.reload(null, false);
                        }
                        $('#taxClientFormModal').modal('hide');
                    },
                    error: function(data){
                        const response = data.responseJSON;
                        //Validator Errors
                        const errors = response.errors;

                        Object.keys(errors).forEach(function(key){
                            errors[key].forEach(function(message){
                                if(key == 'tax_identifier' && message == 'tax_id_duplicate'){
                                    Swal.fire(
                                        {
                                        type: 'warning',
                                        title: "{{ __('entity_forms')['tax_client']['messages']['tax_id_uk_title'] }}",
                                        text: "{{ __('entity_forms')['tax_client']['messages']['tax_id_uk_text'] }}",
                                        confirmButtonColor: '#C34808'
                                        }
                                    );
                                }else{
                                    showToast(message, "#C34808", '#78350F');
                                }
                            });
                        });
                        return;
                    }
                })
            }

            if ($('#action').val() == "Edit") {
                const id= $('#hidden_id').val();
                data.hidden_id=id;
                $.ajax({
                    headers:{
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    url: `/invoicing/clients/${id}`,
                    method: "PATCH",
                    data,
                    success: function (data) {
                        Swal.fire(
                            "{{ __('common_responses_and_messages')['success'] }}",
                            "{{ __('common_responses_and_messages')['updated_successfully'] }}",
                            'success'
                        );
                        $('#taxClientFormModal').modal('hide');
                        $('#tax_client_form')[0].reset();
                        $('#tax_clients_table').DataTable().ajax.reload(null, false);
                    }
                });
            }
        });

        //- Inputs
        $(function () {
            $('#client_is_moral').on('change', toggleExtTaxFormats);
            $('#client_tax_address_country').on('change', toggleExtCountryRequirement);
            $('#client_tax_id').on('change', toggleGenericReceiver);
        });
    });

  //* Special Interactions
    // Tax Data Format
    $('.tax-text').on('input change keyup paste', function () {
        $(this).val($(this).val().toUpperCase());
    });

    // Get address by Zip Code
    $('#client_zip').on('input', async function() {
        try{
            await getTaxAddressByZipAndFillFields({
                zip: $(this).val(),
                municipality_field: '#client_tax_address_municipality',
                city_field: '#client_tax_address_city',
                state_field: '#client_tax_address_state',
                neighborhood_field: '#client_tax_address_neighborhood'
            });
        }catch(error){
            showToast(error.message, "#C34808", '#78350F');
        }
    });

  //* Support Functions
    // Interactions
    function toggleExtTaxFormats() {
        const is_moral = $('#client_is_moral').prop('checked');

        // Define fields requirements and values
        const prefix = is_moral ? 'Moral' : 'Physical';
            window[`define${prefix}TaxIdFormat`]('client_tax_id');
            window[`define${prefix}TaxSystems`]('client_tax_system');
            window[`define${prefix}CfdiUses`]('client_cfdi_use');

        // Visual Adjustments
        $('#person_type').text(is_moral ? "Moral" : "Física");
        toggleExtCountryRequirement();
    }

    function toggleGenericReceiver() {
        const client_tax_id = $('#client_tax_id').val();
        const is_generic_tax_id = client_tax_id === "XAXX010101000";

        if (!is_generic_tax_id) {
            $('#client_zip, #client_tax_systemm, #client_cfdi_use')
                .prop({ readonly: false, disabled: false }).removeClass('disabled-fields');
        } else {
            $('#client_cfdi_use').val("S01").prop({ readonly: true, disabled: true }).addClass('disabled-fields');
            $('#receiver_zip').val(@json($establishment->zip)).prop({ readonly: true, disabled: true }).addClass('disabled-fields');
            $('#client_tax_systemm').val("616").prop({ readonly: true, disabled: true }).addClass('disabled-fields');
        }
    }

    function toggleExtCountryRequirement() {
        const country = $('#client_tax_address_country').val();
        const is_mex_receiver = country === "MEX";

        if (is_mex_receiver) {
            $('#client_tax_id, #client_zip, #client_tax_system, #client_cfdi_use').trigger('change')
                .prop({ readonly: false, disabled: false }).removeClass('disabled-fields');
        } else {
            $('#client_zip').val("00000").prop({ readonly: true, disabled: true }).addClass('disabled-fields');
            $('#client_cfdi_use').val("S01").prop({ readonly: true, disabled: true }).addClass('disabled-fields');
            $('#client_tax_id').val("XEXX010101000").trigger('change').prop({ readonly: true, disabled: true }).addClass('disabled-fields');
            $('#client_tax_system').val("616").prop({ readonly: true, disabled: true }).addClass('disabled-fields');
        }
    }

    // Form General Interactions
    function restoreTaxClientForm() {
        // Seed Form
        $('#client_is_moral').prop('checked', false).trigger('change');

        $(`
            #client_tax_id, #client_legal_name, #client_tax_system, #client_cfdi_use,
            #client_email_billing, #client_phone, #client_zip,
            #client_tax_address_street, #client_tax_address_interior, #client_tax_address_exterior,
            #client_tax_address_city, #client_tax_address_municipality, #client_tax_address_state
        `).val('');
        $('#client_tax_id').val("").trigger("change");
        $('#client_tax_address_country').val("MEX").selectpicker('refresh').trigger("change");
        $('#client_tax_address_neighborhood').empty().selectpicker('refresh');
    }

    // Individual Inputs
    function defineOptionalStates() {
        if (getCountrySettings() !== "MEX") {
            $('#tx-mx-states, #tax-client-mx-states').html("");
            return;
        }

        // Only México States for now
        const tax_mx_states = [
            "Aguascalientes",
            "Baja California",
            "Baja California Sur",
            "Campeche",
            "Chiapas",
            "Chihuahua",
            "Ciudad de México",
            "Coahuila de Zaragoza",
            "Colima",
            "Durango",
            "Guanajuato",
            "Guerrero",
            "Hidalgo",
            "Jalisco",
            "México",
            "Michoacán de Ocampo",
            "Morelos",
            "Nayarit",
            "Nuevo León",
            "Oaxaca",
            "Puebla",
            "Querétaro",
            "Quintana Roo",
            "San Luis Potosí",
            "Sinaloa",
            "Sonora",
            "Tabasco",
            "Tamaulipas",
            "Tlaxcala",
            "Veracruz de Ignacio de la Llave",
            "Yucatán",
            "Zacatecas",
        ];

        let state_options = "";
        tax_mx_states.forEach(state => {
            state_options += `<option value="${state}"></option>`;
        });
        $('#tx-mx-states, #tax-client-mx-states').html(state_options);
    }

    // Messages
    function showToast(text, gradient_from, gradient_to) {
        Toastify({
            text,
            duration: 4000,
            close: false,
            gravity: "bottom",
            position: "center",
            avatar: "{{ asset('images/toast-info-icon.png') }}",
            style: {
                background: `linear-gradient(to right, ${gradient_from}, ${gradient_to})`,
            },
        }).showToast();
    }

</script>
