import { defineComponent, ref, useModel, computed, openBlock, createElementBlock, createVNode, unref, withCtx, createElementVNode, Fragment, renderList, createBlock, createTextVNode, createCommentVNode, renderSlot } from 'vue';
import remixiconSymbol from 'remixicon/fonts/remixicon.symbol.svg';
import { ElInput, ElPopover, ElTabs, ElTabPane, ElLink, ElPagination } from 'element-plus';
import { MeButton } from '../../button/index.mjs';
import { MeSvgIcon } from '../../svg-icon/index.mjs';

"use strict";
const _hoisted_1 = { class: "me-icon-selector" };
const _hoisted_2 = { style: { "display": "flex", "align-items": "center" } };
const _hoisted_3 = { class: "me-icon-selector__list" };
const _hoisted_4 = ["onClick"];
const __default__ = defineComponent({
  name: "me-icon-selector"
});
var script = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    "modelValue": { type: String, ...{ default: "" } },
    "modelModifiers": {}
  },
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const xhr = new XMLHttpRequest();
    xhr.open("GET", remixiconSymbol, false);
    xhr.send();
    var parser = new DOMParser();
    var doc = parser.parseFromString(xhr.responseText, "text/html");
    const els = doc.querySelectorAll('[id^="ri-"]');
    const riList = Array.from(els).map((item) => item.getAttribute("id"));
    const prefix = ref("ri");
    const popoverRef = ref();
    const model = useModel(__props, "modelValue");
    const tabs = {
      ri: {
        label: "\u9884\u8BBE\u56FE\u6807",
        data: riList
      }
    };
    const searchValue = ref("");
    const queryData = ref({
      pageIndex: 1,
      pageSize: 30
    });
    const curData = computed(() => {
      return tabs[prefix.value].data.filter((val) => val.indexOf(searchValue.value) !== -1);
    });
    const dataSource = computed(() => {
      const { pageIndex, pageSize } = queryData.value;
      return curData.value.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
    });
    const clickIcon = (icon) => {
      model.value = icon;
      popoverRef.value.hide();
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(ElInput), {
          modelValue: model.value,
          "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => model.value = $event),
          clearable: "",
          placeholder: "\u9009\u62E9\u56FE\u6807"
        }, {
          prepend: withCtx(() => [
            createVNode(unref(MeSvgIcon), { name: model.value }, null, 8, ["name"])
          ]),
          append: withCtx(() => [
            createVNode(
              unref(ElPopover),
              {
                ref_key: "popoverRef",
                ref: popoverRef,
                "hide-after": 0,
                "popper-class": "icon-selector-popper",
                trigger: "click",
                width: 280
              },
              {
                reference: withCtx(() => [
                  renderSlot(_ctx.$slots, "default", {}, () => [
                    createVNode(unref(MeButton), null, {
                      default: withCtx(() => [..._cache[4] || (_cache[4] = [
                        createTextVNode(
                          " \u9009\u62E9 ",
                          -1
                          /* CACHED */
                        )
                      ])]),
                      _: 1
                      /* STABLE */
                    })
                  ])
                ]),
                default: withCtx(() => [
                  createElementVNode("div", _hoisted_2, [
                    createVNode(unref(ElInput), {
                      modelValue: searchValue.value,
                      "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchValue.value = $event),
                      clearable: "",
                      placeholder: "\u641C\u7D22\u56FE\u6807"
                    }, null, 8, ["modelValue"])
                  ]),
                  createVNode(unref(ElTabs), {
                    modelValue: prefix.value,
                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => prefix.value = $event),
                    class: "demo-tabs"
                  }, {
                    default: withCtx(() => [
                      (openBlock(), createElementBlock(
                        Fragment,
                        null,
                        renderList(tabs, (item, key) => {
                          return createVNode(unref(ElTabPane), {
                            key,
                            label: item.label,
                            name: key
                          }, null, 8, ["label", "name"]);
                        }),
                        64
                        /* STABLE_FRAGMENT */
                      ))
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["modelValue"]),
                  createElementVNode("div", _hoisted_3, [
                    (openBlock(true), createElementBlock(
                      Fragment,
                      null,
                      renderList(dataSource.value, (item, index) => {
                        return openBlock(), createElementBlock("div", {
                          key: index,
                          class: "icon-item flex-center",
                          onClick: ($event) => clickIcon(item)
                        }, [
                          createVNode(unref(MeSvgIcon), { name: item }, null, 8, ["name"])
                        ], 8, _hoisted_4);
                      }),
                      128
                      /* KEYED_FRAGMENT */
                    ))
                  ]),
                  prefix.value === "ri" ? (openBlock(), createBlock(unref(ElLink), {
                    key: 0,
                    href: "https://www.remixicon.cn/",
                    target: "_blank",
                    type: "primary"
                  }, {
                    default: withCtx(() => [..._cache[5] || (_cache[5] = [
                      createTextVNode(
                        "https://www.remixicon.cn",
                        -1
                        /* CACHED */
                      )
                    ])]),
                    _: 1
                    /* STABLE */
                  })) : createCommentVNode("v-if", true),
                  createVNode(unref(ElPagination), {
                    background: "",
                    "current-page": queryData.value.pageIndex,
                    layout: "total, prev, next",
                    "page-size": queryData.value.pageSize,
                    total: tabs[prefix.value].data.length,
                    onCurrentChange: _cache[2] || (_cache[2] = (val) => queryData.value.pageIndex = val)
                  }, null, 8, ["current-page", "page-size", "total"])
                ]),
                _: 3
                /* FORWARDED */
              },
              512
              /* NEED_PATCH */
            )
          ]),
          _: 3
          /* FORWARDED */
        }, 8, ["modelValue"])
      ]);
    };
  }
});

export { script as default };
//# sourceMappingURL=icon-selector.vue2.mjs.map
