"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");
;/* empty css                                                                    */
;/* empty css                                                                      */
;/* empty css                                                                      */
const index$3 = require("../../dialog/index.js");
;/* empty css                                                     */
;/* empty css                                                           */
;/* empty css                                                      */
;/* empty css                                                     */
;/* empty css                                                        */
;/* empty css                                                       */
;/* empty css                                                                  */
;/* empty css                                                        */
;/* empty css                                                      */
;/* empty css                                                       */
const index$2 = require("../../../api/index.js");
;/* empty css                                                                      */
;/* empty css                                                                          */
const eventFlowHandler = require("../../../utils/eventFlow/eventFlowHandler.js");
const getInstance = require("../../../utils/getInstance.js");
;/* empty css           */
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 _hoisted_1 = { class: "text-field-wrapper" };
const _hoisted_2 = { class: "prefix-content" };
const _hoisted_3 = { class: "suffix-content" };
const _hoisted_4 = {
  key: 0,
  class: "data-masking"
};
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "Text",
  props: {
    config: {
      type: Object,
      required: true
    },
    modelValue: {
      type: [String, Number],
      default: ""
    },
    placeholder: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    },
    maxLength: {
      type: Number,
      default: 1e3
    },
    showWordCount: {
      type: Boolean,
      default: false
    },
    prefix: {
      type: String,
      default: ""
    },
    suffix: {
      type: String,
      default: ""
    },
    suffixButton: {
      type: String,
      default: ""
    },
    suffixButtonName: {
      type: String,
      default: ""
    },
    suffixButtonConfig: {
      type: Array,
      default: []
    },
    suffixDialogId: {
      type: String,
      default: ""
    },
    label: {
      type: String,
      default: ""
    },
    dataMasking: {
      type: String,
      default: ""
    },
    formMode: {
      type: String,
      default: ""
    },
    dialogSource: {
      type: String,
      default: ""
    },
    selectionMode: {
      type: String,
      default: ""
    },
    displayFormatText: {
      type: String,
      default: ""
    },
    displayFormat: {
      type: Object,
      default: {}
    },
    fieldMapping: {
      type: Array,
      default: []
    },
    callbackEventConfig: {
      type: Object,
      default: {}
    }
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit: __emit }) {
    const ctx = getInstance.getCurrentVueInstance();
    const props = __props;
    const emit = __emit;
    const inputValue = Vue.computed({
      get: () => props.modelValue,
      set: (val) => {
        emit("update:modelValue", val);
      }
    });
    const realMaxLength = Vue.computed(() => {
      return Math.floor(props.maxLength / (ctx.$dbFieldLengthRatio || 1));
    });
    function handleChange(val) {
      emit("change", val);
    }
    const maskedValue = Vue.computed(() => {
      if (!props.dataMasking || !props.modelValue) return "";
      return "****";
    });
    const instance = Vue.getCurrentInstance();
    const formData = Vue.inject("formData", null);
    const localConfig = Vue.inject("localConfig", null);
    const fieldsData = Vue.inject("fieldsData", null);
    const hiddenFields = Vue.inject("hiddenFields", null);
    const formCtx = Vue.inject("formCtx", null);
    const fieldsList = [
      ...(fieldsData == null ? void 0 : fieldsData.value) || [],
      ...(hiddenFields == null ? void 0 : hiddenFields.value) || []
    ];
    const { getEventHandlers: createEventHandlers } = eventFlowHandler.useEventFlow({
      fields: fieldsList,
      instance,
      localConfig: localConfig == null ? void 0 : localConfig.value,
      components: {
        form: formCtx
      }
    });
    const getEventHandlers = (row, item, eventConfig) => createEventHandlers(item, row, eventConfig);
    async function openSuffixDialog() {
      let dialog = null;
      if (props.dialogSource == "global") {
        const data = await index$2.default.getTemplateDialogById(
          ctx.$http,
          props.suffixDialogId
        );
        dialog = JSON.parse(data.config);
        dialog.id = data.id;
        dialog.name = data.name;
        dialog.selectionMode = props.selectionMode;
        dialog.displayFormat = props.displayFormat;
        dialog.displayFormatText = props.displayFormatText;
        dialog.fieldMapping = props.fieldMapping;
        dialog.callbackEventConfig = props.callbackEventConfig;
      } else if (props.dialogSource == "custom") {
        const dialogsConfig = localConfig.value.dialogs || [];
        dialog = dialogsConfig.find((item) => item.id == props.suffixDialogId);
      }
      if (dialog) {
        index$3.openDialog(
          props.config.fieldName,
          dialog,
          instance,
          formCtx,
          fieldsList,
          formData.value
        ).then((result) => {
          console.log("确定", result);
        }).catch(() => {
          console.log("取消");
        });
      } else {
        console.error(`对话框配置不存在:${props.suffixDialogId}`);
      }
    }
    return (_ctx, _cache) => {
      const _component_el_button = index$1.ElButton;
      const _component_el_input = index.ElInput;
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        Vue.createVNode(_component_el_input, Vue.mergeProps({
          modelValue: inputValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event)
        }, Vue.toHandlers(__props.config.eventHandlers), {
          placeholder: __props.placeholder,
          disabled: __props.disabled,
          readonly: __props.suffixButton == "dialog" ? true : false,
          maxlength: realMaxLength.value,
          "show-word-limit": __props.showWordCount,
          onChange: handleChange,
          clearable: ""
        }), Vue.createSlots({ _: 2 }, [
          __props.prefix ? {
            name: "prefix",
            fn: Vue.withCtx(() => [
              Vue.createElementVNode("span", _hoisted_2, Vue.toDisplayString(__props.prefix), 1)
            ]),
            key: "0"
          } : void 0,
          __props.suffix ? {
            name: "suffix",
            fn: Vue.withCtx(() => [
              Vue.createElementVNode("span", _hoisted_3, Vue.toDisplayString(__props.suffix), 1)
            ]),
            key: "1"
          } : void 0,
          __props.formMode != "query" && __props.suffixButton && __props.suffixButton != "none" ? {
            name: "append",
            fn: Vue.withCtx(() => [
              __props.suffixButton == "dialog" ? (Vue.openBlock(), Vue.createBlock(_component_el_button, {
                key: 0,
                class: "suffixButton",
                onClick: openSuffixDialog
              }, {
                default: Vue.withCtx(() => _cache[1] || (_cache[1] = [
                  Vue.createTextVNode("选择")
                ])),
                _: 1
              })) : __props.suffixButton == "custom" ? (Vue.openBlock(), Vue.createBlock(_component_el_button, Vue.mergeProps({
                key: 1,
                class: "suffixButton"
              }, Vue.toHandlers(getEventHandlers(Vue.unref(formData), {}, __props.suffixButtonConfig))), {
                default: Vue.withCtx(() => [
                  Vue.createTextVNode(Vue.toDisplayString(__props.suffixButtonName), 1)
                ]),
                _: 1
              }, 16)) : Vue.createCommentVNode("", true)
            ]),
            key: "2"
          } : void 0
        ]), 1040, ["modelValue", "placeholder", "disabled", "readonly", "maxlength", "show-word-limit"]),
        __props.dataMasking ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_4, Vue.toDisplayString(maskedValue.value), 1)) : Vue.createCommentVNode("", true)
      ]);
    };
  }
});
const _Text = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-b509ac94"]]);
exports.default = _Text;
