"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../node_modules/element-plus/es/index.js");
;/* empty css                                                       */
;/* empty css                                                           */
;/* empty css                                                            */
const Vue = require("vue");
const index$2 = require("../../../node_modules/@element-plus/icons-vue/dist/index.js");
const TemplateDialog = require("./TemplateDialog.vue.js");
;/* empty css                                                           */
;/* empty css                                                             */
require("./TemplateSelector.vue.js");
const _pluginVue_exportHelper = require("../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../node_modules/element-plus/es/components/input/index.js");
const index$1 = require("../../../node_modules/element-plus/es/components/button/index.js");
const index$3 = require("../../../node_modules/element-plus/es/components/message/index.js");
const _sfc_main = {
  __name: "TemplateSelector",
  props: {
    modelValue: {
      type: String,
      default: ""
    },
    templateKey: {
      type: String,
      default: ""
    },
    templateType: {
      type: String,
      default: ""
    },
    templateId: {
      type: String,
      default: ""
    }
  },
  emits: [
    "update:modelValue",
    "update:templateKey",
    "update:templateId",
    "confirm"
  ],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const modelValue = Vue.computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const dialogVisible = Vue.ref(false);
    function openDialog() {
      dialogVisible.value = true;
    }
    function editTemplate() {
      const pkId = props.templateId;
      if (!pkId) {
        index$3.ElMessage.warning("请先选择模板");
        return;
      }
      const currentUrl = window.location.href;
      const urlObj = new URL(currentUrl);
      urlObj.searchParams.set("pkId", pkId);
      const newUrl = urlObj.toString();
      window.open(newUrl, "_blank");
    }
    function handleDialogConfirm({ row, context }) {
      modelValue.value = row.templateName;
      emit("update:templateKey", row.templateKey);
      emit("update:templateId", row.pkId);
      emit("confirm", context);
    }
    function handleDialogClose() {
    }
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_el_input = index.ElInput;
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        Vue.createVNode(_component_el_input, {
          modelValue: modelValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
          placeholder: __props.templateType == "table" ? "请选择列表" : "请选择表单",
          readonly: ""
        }, Vue.createSlots({
          append: Vue.withCtx(() => [
            Vue.createVNode(_component_el_button, {
              icon: Vue.unref(index$2.Setting),
              onClick: openDialog
            }, null, 8, ["icon"])
          ]),
          _: 2
        }, [
          modelValue.value ? {
            name: "prepend",
            fn: Vue.withCtx(() => [
              Vue.createVNode(_component_el_button, {
                icon: Vue.unref(index$2.Edit),
                onClick: editTemplate
              }, null, 8, ["icon"])
            ]),
            key: "0"
          } : void 0
        ]), 1032, ["modelValue", "placeholder"]),
        Vue.createVNode(TemplateDialog.default, {
          modelValue: dialogVisible.value,
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dialogVisible.value = $event),
          "template-type": __props.templateType,
          title: __props.templateType == "table" ? "选择列表" : "选择表单",
          onConfirm: handleDialogConfirm,
          onClose: handleDialogClose
        }, null, 8, ["modelValue", "template-type", "title"])
      ], 64);
    };
  }
};
const TemplateSelector = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-5026a7f4"]]);
exports.default = TemplateSelector;
