import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                     */
/* empty css                                                                  */
/* empty css                                                                    */
/* empty css                                                                          */
/* empty css                                                                 */
/* empty css                                                                       */
/* empty css                                                                     */
/* empty css                                                                  */
/* empty css                                                               */
/* empty css                                                                  */
/* empty css                                                                        */
/* empty css                                                                  */
/* empty css                                                                 */
/* empty css                                                                          */
/* empty css                                                                    */
/* empty css                                                                  */
/* empty css                                                                             */
import "../../../../../node_modules/element-plus/theme-chalk/el-date-picker.css.mjs";
import "../../../../../node_modules/element-plus/theme-chalk/el-tooltip.css.mjs";
/* empty css                                                                */
import { getCurrentInstance, computed, createElementBlock, openBlock, createBlock, createCommentVNode, createSlots, withCtx, Fragment, normalizeProps, mergeProps, createElementVNode, toDisplayString, createVNode, createTextVNode, renderList, unref } from "vue";
import { useOptions } from "../../../utils/optionLoader.mjs";
/* empty css                              */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElFormItem } from "../../../../../node_modules/element-plus/es/components/form/index.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 { ElDatePicker } from "../../../../../node_modules/element-plus/es/components/date-picker/index.mjs";
import { ElCascader } from "../../../../../node_modules/element-plus/es/components/cascader/index.mjs";
import { ElSelect, ElOption } from "../../../../../node_modules/element-plus/es/components/select/index.mjs";
import { ElRadioGroup, ElRadio } from "../../../../../node_modules/element-plus/es/components/radio/index.mjs";
import { ElCheckboxGroup, ElCheckbox } from "../../../../../node_modules/element-plus/es/components/checkbox/index.mjs";
import { ElSwitch } from "../../../../../node_modules/element-plus/es/components/switch/index.mjs";
import { ElLink } from "../../../../../node_modules/element-plus/es/components/link/index.mjs";
import { ElTooltip } from "../../../../../node_modules/element-plus/es/components/tooltip/index.mjs";
const _hoisted_1 = { class: "component-preview" };
const _hoisted_2 = {
  key: 0,
  class: "iconfont icon-iconZheng credit-icon"
};
const _hoisted_3 = {
  key: 1,
  class: "iconfont icon-iconJian regulation-icon"
};
const _hoisted_4 = { key: 3 };
const _hoisted_5 = { class: "prefix-content" };
const _hoisted_6 = { class: "suffix-content" };
const _hoisted_7 = { class: "prefix-content" };
const _hoisted_8 = { class: "suffix-content" };
const _sfc_main = {
  __name: "ComponentPreviewWrapper",
  props: {
    componentData: {
      type: Object,
      required: true
    }
  },
  setup(__props) {
    const currentInstance = getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    const commProps = computed(() => {
      return {
        disabled: props.componentData.disabled,
        readonly: props.componentData.readOnly,
        placeholder: props.componentData.placeholder || "",
        modelValue: props.componentData.defaultValue,
        maxlength: props.componentData.maxLength,
        showWordLimit: props.componentData.showWordCount || false
      };
    });
    const { options } = useOptions(ctx, props.componentData);
    const cascaderPropsDataValue = computed(() => {
      let propsData = props.componentData.propsData || {};
      if (props.componentData.fieldType == "area" || props.componentData.fieldType == "industry") {
        propsData = {
          value: "optCode",
          label: "optName"
        };
      }
      return {
        ...propsData,
        multiple: props.componentData.multiple,
        checkStrictly: props.componentData.checkStrictly
      };
    });
    const cascaderOptions = computed(() => {
      var _a, _b;
      let oriOptions = options.value;
      let idField = (_a = props.componentData.optionConfig) == null ? void 0 : _a.idField;
      let pidField = (_b = props.componentData.optionConfig) == null ? void 0 : _b.pidField;
      if (props.componentData.fieldType == "area" || props.componentData.fieldType == "industry") {
        idField = "dicId";
        pidField = "pdicId";
      }
      const treeData = flatToTree(
        oriOptions,
        idField,
        pidField,
        props.componentData.maxLevel
      );
      return treeData;
    });
    function flatToTree(list, idKey = "id", pidKey = "pid", maxLevel = 10) {
      const data = JSON.parse(JSON.stringify(list));
      const nodeMap = {};
      data.forEach((node) => {
        nodeMap[node[idKey]] = node;
        node.children = node.children || [];
        node.level = 1;
      });
      const tree = [];
      data.forEach((node) => {
        const parentId = node[pidKey];
        const parentNode = nodeMap[parentId];
        if (parentNode && parentNode.level < maxLevel) {
          node.level = parentNode.level + 1;
          parentNode.children.push(node);
        } else {
          tree.push(node);
        }
      });
      return tree;
    }
    const computedFormat = computed(() => {
      const formatMap = {
        date: "YYYY-MM-DD",
        week: "YYYY年第w周",
        month: "YYYY-MM",
        year: "YYYY",
        datetime: "YYYY-MM-DD HH:mm:ss"
      };
      return formatMap[props.componentData.dateType] || "YYYY-MM-DD";
    });
    return (_ctx, _cache) => {
      const _component_el_link = ElLink;
      const _component_el_tooltip = ElTooltip;
      const _component_el_button = ElButton;
      const _component_el_input = ElInput;
      const _component_el_date_picker = ElDatePicker;
      const _component_el_cascader = ElCascader;
      const _component_el_option = ElOption;
      const _component_el_select = ElSelect;
      const _component_el_radio = ElRadio;
      const _component_el_radio_group = ElRadioGroup;
      const _component_el_checkbox = ElCheckbox;
      const _component_el_checkbox_group = ElCheckboxGroup;
      const _component_el_switch = ElSwitch;
      const _component_el_form_item = ElFormItem;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        __props.componentData.fieldType != "blank" ? (openBlock(), createBlock(_component_el_form_item, {
          key: 0,
          placeholder: __props.componentData.placeholder,
          required: __props.componentData.required,
          class: "preview-form-item"
        }, createSlots({
          default: withCtx(() => [
            __props.componentData.labelMode != "label" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
              __props.componentData.fieldType == "text" ? (openBlock(), createBlock(_component_el_input, normalizeProps(mergeProps({ key: 0 }, commProps.value)), createSlots({ _: 2 }, [
                __props.componentData.prefix ? {
                  name: "prefix",
                  fn: withCtx(() => [
                    createElementVNode("span", _hoisted_5, toDisplayString(__props.componentData.prefix), 1)
                  ]),
                  key: "0"
                } : void 0,
                __props.componentData.suffix ? {
                  name: "suffix",
                  fn: withCtx(() => [
                    createElementVNode("span", _hoisted_6, toDisplayString(__props.componentData.suffix), 1)
                  ]),
                  key: "1"
                } : void 0,
                !__props.componentData.disabled && __props.componentData.suffixButton && __props.componentData.suffixButton != "none" ? {
                  name: "append",
                  fn: withCtx(() => [
                    createVNode(_component_el_button, { class: "suffixButton" }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(__props.componentData.suffixButton == "dialog" ? __props.componentData.suffixDialogName ? __props.componentData.suffixDialogName : "选择" : __props.componentData.suffixButtonName), 1)
                      ]),
                      _: 1
                    })
                  ]),
                  key: "2"
                } : void 0
              ]), 1040)) : __props.componentData.fieldType == "userSelect" || __props.componentData.fieldType == "roleSelect" || __props.componentData.fieldType == "orgSelect" ? (openBlock(), createBlock(_component_el_input, normalizeProps(mergeProps({ key: 1 }, commProps.value)), createSlots({ _: 2 }, [
                !__props.componentData.readOnly && !__props.componentData.disabled ? {
                  name: "append",
                  fn: withCtx(() => [
                    createVNode(_component_el_button, { class: "suffixButton" }, {
                      default: withCtx(() => _cache[1] || (_cache[1] = [
                        createTextVNode("选择")
                      ])),
                      _: 1
                    })
                  ]),
                  key: "0"
                } : void 0
              ]), 1040)) : __props.componentData.fieldType == "textarea" ? (openBlock(), createBlock(_component_el_input, mergeProps({
                key: 2,
                rows: 4,
                type: "textarea"
              }, commProps.value, {
                resize: "none",
                style: { "height": "100%" }
              }), null, 16)) : createCommentVNode("", true),
              __props.componentData.fieldType == "number" ? (openBlock(), createBlock(_component_el_input, mergeProps({ key: 3 }, commProps.value, { controls: false }), createSlots({ _: 2 }, [
                __props.componentData.prefix ? {
                  name: "prefix",
                  fn: withCtx(() => [
                    createElementVNode("span", _hoisted_7, toDisplayString(__props.componentData.prefix), 1)
                  ]),
                  key: "0"
                } : void 0,
                __props.componentData.suffix ? {
                  name: "suffix",
                  fn: withCtx(() => [
                    createElementVNode("span", _hoisted_8, toDisplayString(__props.componentData.suffix), 1)
                  ]),
                  key: "1"
                } : void 0,
                !__props.componentData.disabled && __props.componentData.suffixButton && __props.componentData.suffixButton != "none" ? {
                  name: "append",
                  fn: withCtx(() => [
                    createVNode(_component_el_button, { class: "suffixButton" }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(__props.componentData.suffixButton == "dialog" ? __props.componentData.suffixDialogName ? __props.componentData.suffixDialogName : "选择" : __props.componentData.suffixButtonName), 1)
                      ]),
                      _: 1
                    })
                  ]),
                  key: "2"
                } : void 0
              ]), 1040)) : __props.componentData.fieldType == "date" ? (openBlock(), createBlock(_component_el_date_picker, mergeProps({ key: 4 }, commProps.value, {
                type: __props.componentData.dateType || "date",
                format: computedFormat.value,
                style: { "width": "100%" }
              }), null, 16, ["type", "format"])) : __props.componentData.fieldType == "cascader" || __props.componentData.fieldType == "area" || __props.componentData.fieldType == "industry" ? (openBlock(), createBlock(_component_el_cascader, mergeProps({ key: 5 }, commProps.value, {
                options: cascaderOptions.value,
                props: cascaderPropsDataValue.value,
                "show-all-levels": __props.componentData.showFullPath,
                style: { "width": "100%" }
              }), null, 16, ["options", "props", "show-all-levels"])) : __props.componentData.fieldType == "select" || __props.componentData.fieldType == "multipleSelection" ? (openBlock(), createBlock(_component_el_select, mergeProps({ key: 6 }, commProps.value, {
                multiple: __props.componentData.fieldType == "multipleSelection"
              }), {
                default: withCtx(() => [
                  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(options), (option) => {
                    return openBlock(), createBlock(_component_el_option, {
                      key: option.value,
                      label: option.label,
                      value: option.value
                    }, null, 8, ["label", "value"]);
                  }), 128))
                ]),
                _: 1
              }, 16, ["multiple"])) : __props.componentData.fieldType == "radio" ? (openBlock(), createBlock(_component_el_radio_group, normalizeProps(mergeProps({ key: 7 }, commProps.value)), {
                default: withCtx(() => [
                  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(options), (option) => {
                    return openBlock(), createBlock(_component_el_radio, {
                      key: option.value,
                      value: option.value
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(option.label), 1)
                      ]),
                      _: 2
                    }, 1032, ["value"]);
                  }), 128))
                ]),
                _: 1
              }, 16)) : __props.componentData.fieldType == "checkbox" ? (openBlock(), createBlock(_component_el_checkbox_group, normalizeProps(mergeProps({ key: 8 }, commProps.value)), {
                default: withCtx(() => [
                  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(options), (option) => {
                    return openBlock(), createBlock(_component_el_checkbox, {
                      key: option.value,
                      value: option.value
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(option.label), 1)
                      ]),
                      _: 2
                    }, 1032, ["value"]);
                  }), 128))
                ]),
                _: 1
              }, 16)) : createCommentVNode("", true),
              __props.componentData.fieldType == "switch" ? (openBlock(), createBlock(_component_el_switch, normalizeProps(mergeProps({ key: 9 }, commProps.value)), null, 16)) : createCommentVNode("", true),
              __props.componentData.fieldType == "upload" ? (openBlock(), createBlock(_component_el_input, normalizeProps(mergeProps({ key: 10 }, commProps.value)), null, 16)) : createCommentVNode("", true)
            ], 64)) : createCommentVNode("", true)
          ]),
          _: 2
        }, [
          __props.componentData.labelMode != "input" ? {
            name: "label",
            fn: withCtx(() => {
              var _a;
              return [
                __props.componentData.credit ? (openBlock(), createElementBlock("i", _hoisted_2)) : createCommentVNode("", true),
                __props.componentData.regulation ? (openBlock(), createElementBlock("i", _hoisted_3)) : createCommentVNode("", true),
                __props.componentData.labelLink ? (openBlock(), createBlock(_component_el_link, {
                  key: 2,
                  type: "primary"
                }, {
                  default: withCtx(() => [
                    createTextVNode(toDisplayString(__props.componentData.label), 1)
                  ]),
                  _: 1
                })) : (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(__props.componentData.label), 1)),
                ((_a = __props.componentData.tooltip) == null ? void 0 : _a.trim()) ? (openBlock(), createBlock(_component_el_tooltip, {
                  key: 4,
                  content: __props.componentData.tooltip,
                  placement: "top"
                }, {
                  default: withCtx(() => _cache[0] || (_cache[0] = [
                    createElementVNode("i", { class: "iconfont icon-tooltip info-icon" }, null, -1)
                  ])),
                  _: 1
                }, 8, ["content"])) : createCommentVNode("", true)
              ];
            }),
            key: "0"
          } : void 0
        ]), 1032, ["placeholder", "required"])) : createCommentVNode("", true)
      ]);
    };
  }
};
const ComponentPreviewWrapper = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-3fc3e6c0"]]);
export {
  ComponentPreviewWrapper as default
};
