$(function() {
  'use strict'

  if (!$.fn.select2) {
    return;
  }

  function initSelect2($elements, options) {
    $elements.each(function() {
      var $el = $(this);
      if ($el.hasClass("select2-hidden-accessible")) {
        return;
      }
      var placeholder = $el.data("placeholder");
      var config = $.extend({}, options);
      if (placeholder) {
        config.placeholder = placeholder;
        config.allowClear = true;
      }
      $el.select2(config);
    });
  }

  if ($(".select2").length) {
    initSelect2($(".select2"), {
      width: '100%',
      minimumResultsForSearch: 0
    });
  }
  if ($(".js-example-basic-single").length) {
    initSelect2($(".js-example-basic-single"), {
      width: '100%',
      minimumResultsForSearch: 0
    });
  }
  if ($(".js-example-basic-multiple").length) {
    $(".js-example-basic-multiple").select2();
  }
});
