'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../../hooks/index.js');
var lodashEs = require('lodash-es');
var core = require('@vueuse/core');
var iconsVue = require('@element-plus/icons-vue');
var operateButtonForm = require('./operateButtonForm.js');
var index = require('../../../../../hooks/store/useCustomSettings/index.js');

const _hoisted_1 = { class: "drawer-alert gm-mb-4 gm-flex gm-items-center gm-justify-between gm-rounded gm-border gm-border-cyan-300 gm-bg-cyan-50 gm-px-4 gm-text-sm gm-leading-[40px] gm-text-[#777]" };
const _hoisted_2 = { class: "gm-flex gm-items-center" };
const _hoisted_3 = { class: "gm-ml-2" };
const _hoisted_4 = { class: "gm-text-cyan-500" };
const _hoisted_5 = /* @__PURE__ */ vue.createElementVNode(
  "b",
  { class: "gm-ml-3 gm-text-orange-400" },
  "\u70B9\u51FB\u6309\u94AE\u53EF\u4FEE\u6539\u5F53\u524D\u6309\u94AE\u989C\u8272\uFF01",
  -1
  /* HOISTED */
);
const _hoisted_6 = { class: "p-1" };
const _hoisted_7 = /* @__PURE__ */ vue.createElementVNode(
  "div",
  { class: "text-[14px] gm-mb-2" },
  "\u70B9\u51FB\u4E0B\u5217\u8272\u5757\u53EF\u4FEE\u6539\u6309\u94AE\u989C\u8272",
  -1
  /* HOISTED */
);
const _hoisted_8 = { class: "gm-flex gm-justify-between" };
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmOperateButtonForm"
  },
  __name: "OperateButtonForm",
  props: /* @__PURE__ */ vue.mergeModels(operateButtonForm.operateButtonFormProps, {
    "isShowDrawer": { type: Boolean, ...{
      required: true
    } },
    "isShowDrawerModifiers": {},
    "customBtnPropsList": {
      required: true
    },
    "customBtnPropsListModifiers": {}
  }),
  emits: ["update:isShowDrawer", "update:customBtnPropsList"],
  setup(__props, { expose: __expose }) {
    const isShowDrawer = vue.useModel(__props, "isShowDrawer");
    const customBtnPropsList = vue.useModel(__props, "customBtnPropsList");
    const props = __props;
    const customSettingsStore = index.useCustomSettingsStore();
    const isInited = vue.ref(false);
    const { cloned: clonedCustomBtnList } = core.useCloned(customBtnPropsList);
    const defaultPropsList = vue.computed(() => lodashEs.cloneDeep(props.customDefaultPropsList));
    const popoverVisibles = vue.ref(defaultPropsList.value.map(() => false));
    vue.watch(defaultPropsList, () => {
      popoverVisibles.value = defaultPropsList.value.map(() => false);
    });
    vue.watch(isShowDrawer, (newValue) => {
      if (newValue) {
        clonedCustomBtnList.value = lodashEs.cloneDeep(customBtnPropsList.value);
      }
    });
    const customSettingsValue = vue.computed(() => customSettingsStore.customSettings[props.keyWord]?.[props.type] || []);
    const { cloned: clonedStore } = core.useCloned(customSettingsValue);
    const updateOperate = () => {
      customBtnPropsList.value = clonedCustomBtnList.value;
    };
    const initOperate = async () => {
      try {
        await customSettingsStore.getCustomSettings({ key_word: props.keyWord, type: props.type }, { defaultValue: [] });
      } catch {
      }
      clonedCustomBtnList.value = defaultPropsList.value.map((it) => {
        const findItem = clonedStore.value.find((v) => v.prop === it.prop);
        if (findItem) {
          it.isShow = findItem.isShow;
          it.type = findItem.type;
        }
        return it;
      });
      updateOperate();
      isInited.value = true;
    };
    const checkedNumber = vue.computed(() => {
      return clonedCustomBtnList.value.filter((v) => v.isShow).length;
    });
    const checkedAll = vue.computed(() => clonedCustomBtnList.value.every((v) => v.isShow));
    const isIndeterminate = vue.computed(() => !checkedAll.value && clonedCustomBtnList.value.some((v) => v.isShow));
    const handleCheckAllChange = (val) => {
      clonedCustomBtnList.value.forEach((v) => {
        v.isShow = Boolean(val);
      });
    };
    const setBtnType = (item, index, type) => {
      item.type = type;
      popoverVisibles.value[index] = false;
    };
    const submitLoading = vue.ref(false);
    const onSubmit = async () => {
      try {
        submitLoading.value = true;
        const { data } = await customSettingsStore.addCustomSettings({
          key_word: props.keyWord,
          value: JSON.stringify(clonedCustomBtnList.value),
          type: props.type
        });
        submitLoading.value = false;
        if (data.code !== 200) {
          return;
        }
        isShowDrawer.value = false;
        updateOperate();
      } catch (e) {
        console.error(e);
        submitLoading.value = false;
      }
    };
    const onReset = () => {
      clonedCustomBtnList.value = lodashEs.cloneDeep(props.customDefaultPropsList);
    };
    const onSyncRemote = async () => {
      try {
        submitLoading.value = true;
        await customSettingsStore.syncRemoteSetting({
          key_word: props.keyWord,
          type: props.type
        });
        submitLoading.value = false;
      } catch (e) {
        console.error(e);
        submitLoading.value = false;
      }
    };
    vue.onMounted(() => {
      if (props.disabledRemoteBtn) {
        isInited.value = true;
      } else {
        initOperate();
      }
    });
    __expose({
      isInited
    });
    return (_ctx, _cache) => {
      const _component_gm_icon = vue.resolveComponent("gm-icon");
      const _component_gm_checkbox = vue.resolveComponent("gm-checkbox");
      const _component_gm_table_column = vue.resolveComponent("gm-table-column");
      const _component_gm_button = vue.resolveComponent("gm-button");
      const _component_gm_popover = vue.resolveComponent("gm-popover");
      const _component_gm_table = vue.resolveComponent("gm-table");
      const _component_gm_drawer = vue.resolveComponent("gm-drawer");
      return vue.openBlock(), vue.createBlock(_component_gm_drawer, {
        modelValue: isShowDrawer.value,
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isShowDrawer.value = $event),
        title: "\u81EA\u5B9A\u4E49\u6309\u94AE",
        direction: "rtl",
        size: "500px",
        "append-to-body": "",
        "destroy-on-close": ""
      }, {
        footer: vue.withCtx(() => [
          vue.createElementVNode("div", _hoisted_8, [
            vue.createElementVNode("div", null, [
              vue.createVNode(_component_gm_button, {
                loading: submitLoading.value,
                type: "primary",
                size: "default",
                onClick: onReset
              }, {
                default: vue.withCtx(() => [
                  vue.createTextVNode("\u91CD\u7F6E")
                ]),
                _: 1
                /* STABLE */
              }, 8, ["loading"]),
              vue.createVNode(_component_gm_button, {
                loading: submitLoading.value,
                type: "success",
                size: "default",
                onClick: onSyncRemote
              }, {
                default: vue.withCtx(() => [
                  vue.createTextVNode("\u540C\u6B65")
                ]),
                _: 1
                /* STABLE */
              }, 8, ["loading"])
            ]),
            vue.createElementVNode("div", null, [
              vue.createVNode(_component_gm_button, {
                loading: submitLoading.value,
                size: "default",
                onClick: _cache[0] || (_cache[0] = ($event) => isShowDrawer.value = false)
              }, {
                default: vue.withCtx(() => [
                  vue.createTextVNode("\u53D6\u6D88")
                ]),
                _: 1
                /* STABLE */
              }, 8, ["loading"]),
              vue.createVNode(_component_gm_button, {
                loading: submitLoading.value,
                type: "primary",
                size: "default",
                onClick: onSubmit
              }, {
                default: vue.withCtx(() => [
                  vue.createTextVNode("\u4FDD\u5B58")
                ]),
                _: 1
                /* STABLE */
              }, 8, ["loading"])
            ])
          ])
        ]),
        default: vue.withCtx(() => [
          vue.createElementVNode("section", _hoisted_1, [
            vue.createElementVNode("div", _hoisted_2, [
              vue.createVNode(_component_gm_icon, null, {
                default: vue.withCtx(() => [
                  vue.createVNode(vue.unref(iconsVue.InfoFilled))
                ]),
                _: 1
                /* STABLE */
              }),
              vue.createElementVNode("p", _hoisted_3, [
                vue.createTextVNode(" \u5DF2\u9009\u4E2D "),
                vue.createElementVNode(
                  "span",
                  _hoisted_4,
                  vue.toDisplayString(checkedNumber.value),
                  1
                  /* TEXT */
                ),
                vue.createTextVNode(" \u9879 ")
              ]),
              _hoisted_5
            ])
          ]),
          vue.createVNode(_component_gm_table, {
            data: vue.unref(clonedCustomBtnList),
            "header-cell-style": { background: "#F5F7FA", color: "#333" },
            style: { "width": "100%" }
          }, {
            default: vue.withCtx(() => [
              vue.createVNode(_component_gm_table_column, {
                align: "left",
                width: "80"
              }, {
                header: vue.withCtx(() => [
                  vue.createVNode(_component_gm_checkbox, {
                    "model-value": checkedAll.value,
                    indeterminate: isIndeterminate.value,
                    onChange: handleCheckAllChange
                  }, null, 8, ["model-value", "indeterminate"])
                ]),
                default: vue.withCtx(({ row }) => [
                  vue.createVNode(_component_gm_checkbox, {
                    modelValue: row.isShow,
                    "onUpdate:modelValue": ($event) => row.isShow = $event
                  }, null, 8, ["modelValue", "onUpdate:modelValue"])
                ]),
                _: 1
                /* STABLE */
              }),
              vue.createVNode(_component_gm_table_column, { label: "\u6309\u94AE" }, {
                default: vue.withCtx(({ row, $index }) => [
                  vue.createVNode(_component_gm_popover, {
                    visible: popoverVisibles.value[$index],
                    "onUpdate:visible": ($event) => popoverVisibles.value[$index] = $event,
                    placement: "bottom",
                    width: 330,
                    trigger: "click"
                  }, {
                    reference: vue.withCtx(() => [
                      vue.createVNode(_component_gm_button, {
                        type: row.type || "primary",
                        link: "",
                        size: "small"
                      }, {
                        default: vue.withCtx(() => [
                          vue.createTextVNode(
                            vue.toDisplayString(row.label),
                            1
                            /* TEXT */
                          )
                        ]),
                        _: 2
                        /* DYNAMIC */
                      }, 1032, ["type"])
                    ]),
                    default: vue.withCtx(() => [
                      vue.createElementVNode("div", _hoisted_6, [
                        _hoisted_7,
                        vue.createVNode(_component_gm_button, {
                          type: "primary",
                          size: "small",
                          onClick: ($event) => setBtnType(row, $index, "primary")
                        }, {
                          default: vue.withCtx(() => [
                            vue.createTextVNode(" \u84DD\u8272 ")
                          ]),
                          _: 2
                          /* DYNAMIC */
                        }, 1032, ["onClick"]),
                        vue.createVNode(_component_gm_button, {
                          type: "success",
                          size: "small",
                          onClick: ($event) => setBtnType(row, $index, "success")
                        }, {
                          default: vue.withCtx(() => [
                            vue.createTextVNode(" \u7EFF\u8272 ")
                          ]),
                          _: 2
                          /* DYNAMIC */
                        }, 1032, ["onClick"]),
                        vue.createVNode(_component_gm_button, {
                          type: "info",
                          size: "small",
                          onClick: ($event) => setBtnType(row, $index, "info")
                        }, {
                          default: vue.withCtx(() => [
                            vue.createTextVNode(" \u7070\u8272 ")
                          ]),
                          _: 2
                          /* DYNAMIC */
                        }, 1032, ["onClick"]),
                        vue.createVNode(_component_gm_button, {
                          type: "warning",
                          size: "small",
                          onClick: ($event) => setBtnType(row, $index, "warning")
                        }, {
                          default: vue.withCtx(() => [
                            vue.createTextVNode(" \u6A59\u8272 ")
                          ]),
                          _: 2
                          /* DYNAMIC */
                        }, 1032, ["onClick"]),
                        vue.createVNode(_component_gm_button, {
                          type: "danger",
                          size: "small",
                          onClick: ($event) => setBtnType(row, $index, "danger")
                        }, {
                          default: vue.withCtx(() => [
                            vue.createTextVNode(" \u7EA2\u8272 ")
                          ]),
                          _: 2
                          /* DYNAMIC */
                        }, 1032, ["onClick"])
                      ])
                    ]),
                    _: 2
                    /* DYNAMIC */
                  }, 1032, ["visible", "onUpdate:visible"])
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            _: 1
            /* STABLE */
          }, 8, ["data"])
        ]),
        _: 1
        /* STABLE */
      }, 8, ["modelValue"]);
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=OperateButtonForm.vue2.js.map
