import { defineComponent, useModel, onMounted, openBlock, createElementBlock, createVNode, unref, withCtx, createElementVNode, mergeModels } from 'vue';
import { ElInput } from 'element-plus';
import { RandomType } from './input-random.mjs';
import { MeSvgIcon } from '../../svg-icon/index.mjs';

"use strict";
const _hoisted_1 = { class: "me-input-random" };
const __default__ = defineComponent({
  name: "me-input-random"
});
var script = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: /* @__PURE__ */ mergeModels({
    length: { type: Number, required: true, default: 4 },
    type: { type: Number, required: true, default: 0 }
  }, {
    "modelValue": { type: String },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const inputValue = useModel(__props, "modelValue");
    const numCode = "1234567890";
    const litterCode = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
    const numLitterCode = numCode + litterCode;
    onMounted(() => {
      if (!inputValue.value) {
        getRandomOfType();
      }
    });
    const getRandomOfType = () => {
      switch (props.type) {
        case RandomType.NUM:
          inputValue.value = getRandomRes(numCode);
          break;
        case RandomType.LITTER:
          inputValue.value = getRandomRes(litterCode);
          break;
        case RandomType.NUM_LITTER:
          inputValue.value = getRandomRes(numLitterCode);
          break;
        default:
          break;
      }
    };
    function getRandomRes(code) {
      let res = "";
      for (let i = 0; i < props.length; i++) {
        res += code.charAt(Math.floor(Math.random() * numCode.length));
      }
      return res;
    }
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(ElInput), {
          readonly: "",
          modelValue: inputValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event),
          style: { "max-width": "600px" },
          class: "input-with-select"
        }, {
          append: withCtx(() => [
            createElementVNode("div", {
              style: { "cursor": "pointer" },
              onClick: getRandomOfType
            }, [
              createVNode(unref(MeSvgIcon), { name: "ri-restart-line" })
            ])
          ]),
          _: 1
          /* STABLE */
        }, 8, ["modelValue"])
      ]);
    };
  }
});

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