"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 common = require("../utils/common.js");
;/* empty css                     */
const _pluginVue_exportHelper = require("../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../node_modules/element-plus/es/components/checkbox/index.js");
const index$1 = require("../../../../node_modules/element-plus/es/components/scrollbar/index.js");
const _hoisted_1 = { class: "field-selection" };
const _hoisted_2 = { class: "field-table" };
const _hoisted_3 = { class: "table-header" };
const _hoisted_4 = { class: "header-field" };
const _hoisted_5 = { class: "selection-count" };
const _hoisted_6 = { class: "header-visible" };
const _hoisted_7 = { class: "header-checkbox" };
const _hoisted_8 = { class: "header-editable" };
const _hoisted_9 = { class: "header-checkbox" };
const _hoisted_10 = { class: "table-body" };
const _hoisted_11 = { class: "cell-field" };
const _hoisted_12 = { class: "field-text" };
const _hoisted_13 = { class: "field-label" };
const _hoisted_14 = { class: "field-name" };
const _hoisted_15 = { class: "cell-visible" };
const _hoisted_16 = { class: "cell-editable" };
const _sfc_main = {
  __name: "fieldSelection",
  props: {
    mode: {
      type: Object,
      required: true
    },
    fields: {
      type: Array,
      default: () => []
    }
  },
  setup(__props) {
    const props = __props;
    const copyFields = Vue.ref([]);
    const isUpdatingFromMode = Vue.ref(false);
    const initFields = () => {
      copyFields.value = common.cloneDeep(props.fields);
      copyFields.value.forEach((field) => {
        var _a, _b;
        field.isShow = ((_a = props.mode.showFields) == null ? void 0 : _a.includes(field.id)) || false;
        field.isEdit = ((_b = props.mode.editFields) == null ? void 0 : _b.includes(field.id)) || false;
      });
    };
    initFields();
    Vue.watch(
      () => props.fields,
      () => {
        initFields();
      }
    );
    Vue.watch(
      copyFields,
      () => {
        updateModeConfig();
      },
      { deep: true }
    );
    Vue.watch(
      () => [props.mode.showFields, props.mode.editFields],
      () => {
        if (!isUpdatingFromMode.value) {
          initFields();
        }
      },
      { deep: true }
    );
    const updateModeConfig = () => {
      isUpdatingFromMode.value = true;
      props.mode.showFields = copyFields.value.filter((field) => field.isShow).map((field) => field.id);
      props.mode.editFields = copyFields.value.filter((field) => field.isEdit).map((field) => field.id);
      setTimeout(() => {
        isUpdatingFromMode.value = false;
      }, 0);
    };
    const selectAllVisible = Vue.computed({
      get: () => {
        return copyFields.value.length > 0 && copyFields.value.every((field) => field.isShow);
      },
      set: (value) => {
        copyFields.value.forEach((field) => {
          field.isShow = value;
          if (!value) {
            field.isEdit = false;
          }
        });
      }
    });
    const selectAllEditable = Vue.computed({
      get: () => {
        const visibleFields = copyFields.value.filter((field) => field.isShow);
        return visibleFields.length > 0 && visibleFields.every((field) => field.isEdit);
      },
      set: (value) => {
        copyFields.value.forEach((field) => {
          if (field.isShow) {
            field.isEdit = value;
          }
        });
      }
    });
    const handleSelectAllVisible = (value) => {
      selectAllVisible.value = value;
    };
    const handleSelectAllEditable = (value) => {
      selectAllEditable.value = value;
    };
    const handleVisibleChange = (field, checked) => {
      field.isShow = checked;
      if (!checked && field.isEdit) {
        field.isEdit = false;
      }
    };
    const handleEditableChange = (field, checked) => {
      field.isEdit = checked;
    };
    const visibleFieldsCount = Vue.computed(() => {
      return copyFields.value.filter((field) => field.isShow).length;
    });
    const editableFieldsCount = Vue.computed(() => {
      return copyFields.value.filter((field) => field.isEdit).length;
    });
    return (_ctx, _cache) => {
      const _component_el_checkbox = index.ElCheckbox;
      const _component_el_scrollbar = index$1.ElScrollbar;
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        Vue.createElementVNode("div", _hoisted_2, [
          Vue.createElementVNode("div", _hoisted_3, [
            Vue.createElementVNode("div", _hoisted_4, [
              Vue.createElementVNode("span", _hoisted_5, "已选择 " + Vue.toDisplayString(visibleFieldsCount.value) + " 个可见字段，" + Vue.toDisplayString(editableFieldsCount.value) + " 个可编辑字段", 1)
            ]),
            Vue.createElementVNode("div", _hoisted_6, [
              Vue.createElementVNode("div", _hoisted_7, [
                Vue.createVNode(_component_el_checkbox, {
                  modelValue: selectAllVisible.value,
                  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectAllVisible.value = $event),
                  onChange: handleSelectAllVisible
                }, {
                  default: Vue.withCtx(() => _cache[2] || (_cache[2] = [
                    Vue.createTextVNode(" 可见 ")
                  ])),
                  _: 1
                }, 8, ["modelValue"])
              ])
            ]),
            Vue.createElementVNode("div", _hoisted_8, [
              Vue.createElementVNode("div", _hoisted_9, [
                Vue.createVNode(_component_el_checkbox, {
                  modelValue: selectAllEditable.value,
                  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => selectAllEditable.value = $event),
                  onChange: handleSelectAllEditable
                }, {
                  default: Vue.withCtx(() => _cache[3] || (_cache[3] = [
                    Vue.createTextVNode(" 可编辑 ")
                  ])),
                  _: 1
                }, 8, ["modelValue"])
              ])
            ])
          ]),
          Vue.createElementVNode("div", _hoisted_10, [
            Vue.createVNode(_component_el_scrollbar, null, {
              default: Vue.withCtx(() => [
                (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(copyFields.value, (field) => {
                  return Vue.openBlock(), Vue.createElementBlock("div", {
                    key: field.id,
                    class: "table-row"
                  }, [
                    Vue.createElementVNode("div", _hoisted_11, [
                      Vue.createElementVNode("span", _hoisted_12, [
                        Vue.createElementVNode("span", _hoisted_13, Vue.toDisplayString(field.label), 1),
                        Vue.createElementVNode("span", _hoisted_14, "(" + Vue.toDisplayString(field.fieldName || "未命名") + ")", 1)
                      ])
                    ]),
                    Vue.createElementVNode("div", _hoisted_15, [
                      Vue.createVNode(_component_el_checkbox, {
                        modelValue: field.isShow,
                        "onUpdate:modelValue": ($event) => field.isShow = $event,
                        onChange: (checked) => handleVisibleChange(field, checked)
                      }, null, 8, ["modelValue", "onUpdate:modelValue", "onChange"])
                    ]),
                    Vue.createElementVNode("div", _hoisted_16, [
                      Vue.createVNode(_component_el_checkbox, {
                        modelValue: field.isEdit,
                        "onUpdate:modelValue": ($event) => field.isEdit = $event,
                        onChange: (checked) => handleEditableChange(field, checked),
                        disabled: !field.isShow
                      }, null, 8, ["modelValue", "onUpdate:modelValue", "onChange", "disabled"])
                    ])
                  ]);
                }), 128))
              ]),
              _: 1
            })
          ])
        ])
      ]);
    };
  }
};
const FieldSelection = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-df0c3263"]]);
exports.default = FieldSelection;
