<?= $this->include("themes/_commonPartialsBs/datatables") ?>
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
<?=$this->extend('themes/backend/vuexy/main/defaultlayout') ?>

<?= $this->section("content") ?>
<div class="row">
    <div class="col-12">
		<div class="card card-info">
			<div class="card-header">
        		<h3 class="card-title"><?= $boxTitle ?? $pageTitle ?></h3>
			</div><!--//.card-header -->
			<form id="clienteForm" method="post" class="card-body" action="<?= $formAction ?>">
				<?= csrf_field() ?>
                <div class="card-body">
                    <?= view("themes/_commonPartialsBs/_alertBoxes") ?>
                    <?= !empty($validation->getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?>
                    <?= view("themes/backend/vuexy/form/clientes/cliente/_clienteFormItems") ?>
                </div><!-- /.card-body -->
                <div class="pt-4">
                    <input
                            type="submit"
                            class="btn btn-primary float-start me-sm-3 me-1"
                            name="save"
                            value="<?= lang("Basic.global.Save") ?>"
                    >
                    <?= anchor(route_to("clienteList"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start"]) ?>
                </div><!-- /.card-footer -->
			</form>
        </div><!-- //.card -->
    </div><!--//.col -->
</div><!--//.row -->
<?= $this->endSection() ?>


<?= $this->section("additionalInlineJs") ?>

    $('#soporteId').select2({
        allowClear: false,
        ajax: {
            url: '<?= route_to("menuItemsOfUsers") ?>',
            type: 'post',
            dataType: 'json',

            data: function (params) {
                return {
                    id: 'id_user',
                    text: 'first_name',
                    searchTerm: params.term,
                    <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
                };
            },
            delay: 60,
            processResults: function (response) {

                yeniden(response.<?= csrf_token() ?>);

                return {
                    results: response.menu
                };
            },

            cache: true
        }
    });

    $('#formaPagoId').select2({
        allowClear: false,
        ajax: {
            url: '<?= route_to("menuItemsOfFormasDePagos") ?>',
            type: 'post',
            dataType: 'json',

            data: function (params) {
                return {
                    id: 'id',
                    text: 'nombre',
                    searchTerm: params.term,
                    <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
                };
            },
            delay: 60,
            processResults: function (response) {

                yeniden(response.<?= csrf_token() ?>);

                return {
                    results: response.menu
                };
            },

            cache: true
        }
    });

    $('#paisId').select2({
        allowClear: false,
        ajax: {
            url: '<?= route_to("menuItemsOfPaises") ?>',
            type: 'post',
            dataType: 'json',

            data: function (params) {
                return {
                    id: 'id',
                    text: 'nombre',
                    searchTerm: params.term,
                    <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
                };
            },
            delay: 60,
            processResults: function (response) {

                yeniden(response.<?= csrf_token() ?>);

                return {
                    results: response.menu
                };
            },

            cache: true
        }
    });

    $('#provinciaId').select2({
        allowClear: false,
        ajax: {
            url: '<?= route_to("menuItemsOfProvincias") ?>',
            type: 'post',
            dataType: 'json',

            data: function (params) {
                return {
                    id: 'id',
                    text: 'nombre',
                    searchTerm: params.term,
                    <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
                };
            },
            delay: 60,
            processResults: function (response) {

                yeniden(response.<?= csrf_token() ?>);

                return {
                    results: response.menu
                };
            },

            cache: true
        }
    });

    $('#comunidadAutonomaId').select2({
        allowClear: false,
        ajax: {
            url: '<?= route_to("menuItemsOfComunidadesAutonomas") ?>',
            type: 'post',
            dataType: 'json',

            data: function (params) {
                return {
                    id: 'id',
                    text: 'nombre',
                    searchTerm: params.term,
                    <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
                };
            },
            delay: 60,
            processResults: function (response) {

                yeniden(response.<?= csrf_token() ?>);

                return {
                    results: response.menu
                };
            },

            cache: true
        }
    });

    $('#comercialId').select2({
        allowClear: false,
        ajax: {
            url: '<?= route_to("menuItemsOfUsers") ?>',
            type: 'post',
            dataType: 'json',

            data: function (params) {
                return {
                    id: 'id_user',
                    text: 'first_name',
                    searchTerm: params.term,
                    <?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
                };
            },
            delay: 60,
            processResults: function (response) {

                yeniden(response.<?= csrf_token() ?>);

                return {
                    results: response.menu
                };
            },

            cache: true
        }
    });

<?= $this->endSection() ?>

