import { defineComponent, useModel, useSlots, computed, ref, openBlock, createElementBlock, normalizeStyle, createElementVNode, createBlock, unref, withCtx, Fragment, renderList, createCommentVNode, normalizeClass, toDisplayString, renderSlot, mergeProps, createSlots, createVNode, createTextVNode, mergeModels } from 'vue';
import { ElSelect, ElOption, ElButton, ElInput } from 'element-plus';
import { MeSvgIcon } from '../../svg-icon/index.mjs';
import { MeInputNumber } from '../../input-number/index.mjs';

"use strict";
const _hoisted_1 = {
  key: 1,
  style: { "margin-left": "4px" }
};
const _hoisted_2 = { class: "me-input" };
const _hoisted_3 = {
  key: 3,
  class: "first-button"
};
const _hoisted_4 = {
  key: 1,
  style: { "margin-left": "4px" }
};
const __default__ = defineComponent({
  name: "me-input"
});
var script = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: /* @__PURE__ */ mergeModels({
    btnText: { type: String, required: false, default: "\u786E\u5B9A" },
    mode: { type: String, required: false, default: "number" },
    loading: { type: Boolean, required: false, default: false },
    buttonGroupAppend: { type: Array, required: false },
    buttonGroupPrepend: { type: Array, required: false },
    searchOptions: { type: Array, required: false },
    selectWidth: { type: String, required: false, default: "100px" },
    height: { type: String, required: false, default: "32px" },
    width: { type: String, required: false, default: "150px" },
    focusWidth: { type: String, required: false, default: "0px" },
    controls: { type: Boolean, required: false, default: false }
  }, {
    "modelValue": { type: null },
    "modelModifiers": {},
    "select": {},
    "selectModifiers": {}
  }),
  emits: /* @__PURE__ */ mergeModels(["confirm", "selectChange"], ["update:modelValue", "update:select"]),
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const data = useModel(__props, "modelValue");
    const searchData = useModel(__props, "select");
    const slots = useSlots();
    const isPrepend = computed(() => {
      return props.buttonGroupPrepend || slots["button-group-prepend"];
    });
    const isAppend = computed(() => {
      return props.buttonGroupAppend || slots["button-group-append"];
    });
    const showDefault = computed(() => {
      return isPrepend.value || isAppend.value;
    });
    const inputWidth = ref(props.width);
    const getStyle = computed(() => {
      return {
        width: inputWidth.value,
        transition: "width .3s ease-in-out"
      };
    });
    const inputStyle = computed(() => {
      return {
        "--me-border-b-r-radius": borderBottomRightRadius.value,
        "--me-border-t-r-radius": borderTopRightRadius.value,
        "--me-height": props.height,
        "--me-border-radius": meInputBorderStyle.value,
        "--me-select-width": props.selectWidth
      };
    });
    const meInputBorderStyle = computed(() => {
      if (searchData.value) {
        return "0px";
      }
      if (slots["append"] || slots["prepend"]) {
        return;
      }
      if (!slots["button-group-prepend"]) {
        return "4px 0px 0px 4px";
      }
      if (!slots["button-group-append"]) {
        return "0px 4px 4px 0px";
      }
    });
    const borderBottomRightRadius = computed(() => {
      if (slots["button-group"]) {
        return "0px";
      } else {
        return "4px";
      }
    });
    const borderTopRightRadius = computed(() => {
      if (slots["button-group"]) {
        return "0px";
      } else {
        return "4px";
      }
    });
    const handleInputFocus = () => {
      inputWidth.value = `calc(${props.width} + ${props.focusWidth})`;
    };
    const handleInputBlur = () => {
      inputWidth.value = props.width;
    };
    const handleConfirm = () => {
      emit("confirm");
    };
    const searchChange = (value) => {
      emit("selectChange", value);
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(
        "div",
        {
          class: "me-input",
          style: normalizeStyle({ ...inputStyle.value })
        },
        [
          createElementVNode(
            "div",
            {
              class: "tag-input input-group",
              style: normalizeStyle({ height: props.height, width: props.width })
            },
            [
              searchData.value ? (openBlock(), createBlock(unref(ElSelect), {
                key: 0,
                onChange: searchChange,
                modelValue: searchData.value,
                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchData.value = $event),
                class: "search-select",
                style: normalizeStyle({ width: __props.selectWidth, height: props.height })
              }, {
                default: withCtx(() => [
                  (openBlock(true), createElementBlock(
                    Fragment,
                    null,
                    renderList(__props.searchOptions, (item) => {
                      return openBlock(), createBlock(unref(ElOption), {
                        key: item.value,
                        label: item.label,
                        value: item.value
                      }, null, 8, ["label", "value"]);
                    }),
                    128
                    /* KEYED_FRAGMENT */
                  ))
                ]),
                _: 1
                /* STABLE */
              }, 8, ["modelValue", "style"])) : createCommentVNode("v-if", true),
              createCommentVNode(" buttonGroupPrepend \u524D\u7F6E\u6309\u94AE\u7EC4 "),
              __props.buttonGroupPrepend ? (openBlock(), createElementBlock(
                "div",
                {
                  key: 1,
                  class: normalizeClass(["button-group", { prepend: isPrepend.value }])
                },
                [
                  (openBlock(true), createElementBlock(
                    Fragment,
                    null,
                    renderList(__props.buttonGroupPrepend, (item, index) => {
                      return openBlock(), createBlock(unref(ElButton), {
                        loading: item.loading,
                        onClick: item.handle,
                        style: normalizeStyle({
                          borderTopRightRadius: index == __props.buttonGroupPrepend.length - 1 ? "4px" : "0px",
                          borderBottomRightRadius: index == __props.buttonGroupPrepend.length - 1 ? "4px" : "0px",
                          width: item.text ? "auto" : item.width || "34px"
                        })
                      }, {
                        default: withCtx(() => [
                          item.icon ? (openBlock(), createBlock(unref(MeSvgIcon), {
                            key: 0,
                            name: item.icon
                          }, null, 8, ["name"])) : createCommentVNode("v-if", true),
                          item.text ? (openBlock(), createElementBlock(
                            "span",
                            _hoisted_1,
                            toDisplayString(item.text),
                            1
                            /* TEXT */
                          )) : createCommentVNode("v-if", true)
                        ]),
                        _: 2
                        /* DYNAMIC */
                      }, 1032, ["loading", "onClick", "style"]);
                    }),
                    256
                    /* UNKEYED_FRAGMENT */
                  ))
                ],
                2
                /* CLASS */
              )) : (openBlock(), createElementBlock(
                "div",
                {
                  key: 2,
                  class: normalizeClass(["button-group", { prepend: isPrepend.value }])
                },
                [
                  renderSlot(_ctx.$slots, "button-group-prepend")
                ],
                2
                /* CLASS */
              )),
              createCommentVNode(" \u8F93\u5165\u6846 "),
              createElementVNode("div", _hoisted_2, [
                renderSlot(_ctx.$slots, "input", {}, () => [
                  __props.mode === "number" ? (openBlock(), createBlock(unref(MeInputNumber), mergeProps({
                    key: 0,
                    onFocus: handleInputFocus,
                    onBlur: handleInputBlur,
                    style: getStyle.value,
                    modelValue: data.value,
                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => data.value = $event)
                  }, _ctx.$attrs, { controls: __props.controls }), null, 16, ["style", "modelValue", "controls"])) : createCommentVNode("v-if", true),
                  __props.mode === "text" ? (openBlock(), createBlock(unref(ElInput), mergeProps({
                    key: 1,
                    onFocus: handleInputFocus,
                    onBlur: handleInputBlur,
                    style: getStyle.value,
                    clearable: ""
                  }, _ctx.$attrs, {
                    modelValue: data.value,
                    "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => data.value = $event)
                  }), createSlots({
                    _: 2
                    /* DYNAMIC */
                  }, [
                    renderList(_ctx.$slots, (item, key) => {
                      return {
                        name: key,
                        fn: withCtx(() => [
                          renderSlot(_ctx.$slots, key)
                        ])
                      };
                    })
                  ]), 1040, ["style", "modelValue"])) : createCommentVNode("v-if", true)
                ])
              ]),
              createCommentVNode(" \u9ED8\u8BA4 \u6309\u94AE\u7EC4 "),
              !showDefault.value ? (openBlock(), createElementBlock("div", _hoisted_3, [
                renderSlot(_ctx.$slots, "default", {}, () => [
                  createVNode(unref(ElButton), {
                    style: {
                      borderTopLeftRadius: "0px",
                      borderBottomLeftRadius: "0px"
                    },
                    loading: __props.loading,
                    onClick: handleConfirm
                  }, {
                    default: withCtx(() => [
                      createTextVNode(
                        toDisplayString(__props.btnText),
                        1
                        /* TEXT */
                      )
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["loading"])
                ])
              ])) : createCommentVNode("v-if", true),
              createCommentVNode(" buttonGroupAppend \u540E\u7F6E\u6309\u94AE\u7EC4"),
              __props.buttonGroupAppend ? (openBlock(), createElementBlock(
                "div",
                {
                  key: 4,
                  class: normalizeClass(["button-group", { append: isAppend.value }])
                },
                [
                  (openBlock(true), createElementBlock(
                    Fragment,
                    null,
                    renderList(__props.buttonGroupAppend, (item, index) => {
                      return openBlock(), createBlock(unref(ElButton), {
                        loading: item.loading,
                        onClick: item.handle,
                        style: normalizeStyle({
                          borderTopRightRadius: index == __props.buttonGroupAppend.length - 1 ? "4px" : "0px",
                          borderBottomRightRadius: index == __props.buttonGroupAppend.length - 1 ? "4px" : "0px",
                          width: item.text ? "auto" : item.width || "34px"
                        })
                      }, {
                        default: withCtx(() => [
                          item.icon ? (openBlock(), createBlock(unref(MeSvgIcon), {
                            key: 0,
                            name: item.icon
                          }, null, 8, ["name"])) : createCommentVNode("v-if", true),
                          item.text ? (openBlock(), createElementBlock(
                            "span",
                            _hoisted_4,
                            toDisplayString(item.text),
                            1
                            /* TEXT */
                          )) : createCommentVNode("v-if", true)
                        ]),
                        _: 2
                        /* DYNAMIC */
                      }, 1032, ["loading", "onClick", "style"]);
                    }),
                    256
                    /* UNKEYED_FRAGMENT */
                  ))
                ],
                2
                /* CLASS */
              )) : (openBlock(), createElementBlock(
                "div",
                {
                  key: 5,
                  class: normalizeClass(["button-group", { append: isAppend.value }])
                },
                [
                  renderSlot(_ctx.$slots, "button-group-append")
                ],
                2
                /* CLASS */
              ))
            ],
            4
            /* STYLE */
          )
        ],
        4
        /* STYLE */
      );
    };
  }
});

export { script as default };
//# sourceMappingURL=input.vue2.mjs.map
