$(".subscribe-select-two").select2({
  ajax: {
    url: mpPanelBaseUrl + "/subscribe-request",
    type: "post",
    dataType: 'json',
    delay: 250,
    data: function (params) {
      return {
        search: $.trim(params.term)
      };
    },
    processResults: function (data) {
      return {
        results: data
      };
    },
    cache: true
  },
  dir: "rtl",
  language: {
    inputTooShort: function() {
      return "جستجو در اشتراکها";
    },
    noResults: function () {
      return "جستجو نتیجه‌ای نداشت";
    }
  },
  minimumInputLength: 1,
  templateResult: formatSubscribe,
  templateSelection: formatSubscribeSelection
});

function formatSubscribe (subscribe) {
  if (subscribe.loading) {
    return subscribe.text;
  }

  let $container = $(
    "<div class='select2-result clearfix'>" +
      "<div class='select2-result-meta'>" +
        "<div class='select2-result-text'></div>" +
        "<div class='select2-result-summary'></div>" +
      "</div>" +
    "</div>"
  );

  $container.find(".select2-result-text").text(subscribe.text);
  $container.find(".select2-result-summary").text(subscribe.summary);

  return $container;
}

function formatSubscribeSelection (subscribe) {
  return subscribe.text ;
}