"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.inicializarSelector = inicializarSelector;
function inicializarSelector() {
  var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : $('select');
  var configuracionSelector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
    language: {
      noResults: function noResults() {
        return "";
      },
      searching: function searching() {
        return "Buscando...";
      },
      loadingMore: function loadingMore() {
        return "Cargando más resultados...";
      }
    },
    minimumResultsForSearch: null,
    templateResult: function templateResult(data, opcion) {
      !data.id && (data.text = ' ');
      if (data.id === 'crearRegistro') {
        data.text = $("<div>").addClass("row justify-content-between").append("\n  \n            <div class=\"col-auto\">\n              <span class=\"text-decoration-underline\">\n                Crear nuevo registro\n              </span>\n            </div>\n  \n            <div\n              class=\"col-auto\"\n              style=\"\n                width: 15px;\n                height: 15px;\n                border: 1px solid #fff;\n                border-radius: 1em;\n                background-color: var(--bs-success);\n                font-size: 9px;\n                text-align: center;\n                color: #fff\n              \"\n            >\n              +\n            </div>\n  \n        ");
      }
      $(opcion, '.select2-results__options').click(function () {
        $(this).parent().parent().parent().css('z-index', '1040') && $('#ventanaDialogoCreacion').modal('show');
      });
      return data.text;
    }
  };
  $(selector).select2(configuracionSelector);
  $(selector).map(function (indice, elemento) {
    // $(elemento).on('change', function() {

    //   console.log(this.value)

    // });

    // elemento.disabled = elemento.options.length <= 1;

    // elemento.selectedIndex = Number(
    //   elemento.options.length <= 1
    // );

    $('form').has(elemento).on('reset', function () {
      setTimeout(function () {
        $(elemento).prop({
          disabled: elemento.getAttribute('disabled') === '' || elemento.options.length <= 1,
          selectedIndex: Number(elemento.options.length && elemento.options[0].value === 'crearRegistro')
        });
        elemento.options.length && (elemento.options[0].disabled = elemento.options[0].value === 'crearRegistro');
      }, 1);

      // $(elemento).children().first().val() === 'crearRegistro' &&
      // $(elemento).children().first().attr('disabled', 'disabled')
    });
  });

  // $(selector).change(function() {

  //   $(select).select2('trigger', 'select', {
  //     data: {
  //       id: 4
  //     }
  //   })

  // })
}