import "../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                       */
/* empty css                                                           */
/* empty css                                                            */
import { computed, ref, createElementBlock, openBlock, Fragment, createVNode, createSlots, withCtx, unref } from "vue";
import { Setting as setting_default, Edit as edit_default } from "../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
import TemplateDialog from "./TemplateDialog.vue.mjs";
/* empty css                                                           */
/* empty css                                                             */
import "./TemplateSelector.vue.mjs";
import _export_sfc from "../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElInput } from "../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElButton } from "../../../node_modules/element-plus/es/components/button/index.mjs";
import { ElMessage } from "../../../node_modules/element-plus/es/components/message/index.mjs";
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 = computed({
      get: () => props.modelValue,
      set: (val) => emit("update:modelValue", val)
    });
    const dialogVisible = ref(false);
    function openDialog() {
      dialogVisible.value = true;
    }
    function editTemplate() {
      const pkId = props.templateId;
      if (!pkId) {
        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 = ElButton;
      const _component_el_input = ElInput;
      return openBlock(), createElementBlock(Fragment, null, [
        createVNode(_component_el_input, {
          modelValue: modelValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
          placeholder: __props.templateType == "table" ? "请选择列表" : "请选择表单",
          readonly: ""
        }, createSlots({
          append: withCtx(() => [
            createVNode(_component_el_button, {
              icon: unref(setting_default),
              onClick: openDialog
            }, null, 8, ["icon"])
          ]),
          _: 2
        }, [
          modelValue.value ? {
            name: "prepend",
            fn: withCtx(() => [
              createVNode(_component_el_button, {
                icon: unref(edit_default),
                onClick: editTemplate
              }, null, 8, ["icon"])
            ]),
            key: "0"
          } : void 0
        ]), 1032, ["modelValue", "placeholder"]),
        createVNode(TemplateDialog, {
          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__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-5026a7f4"]]);
export {
  TemplateSelector as default
};
