var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var stdin_exports = {};
__export(stdin_exports, {
  SettingDrawer: () => SettingDrawer,
  getFormatMessage: () => getFormatMessage,
  settingDrawerProps: () => settingDrawerProps
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_icons_vue = require("@ant-design/icons-vue");
var import_pro_provider = require("@antdv/pro-provider");
var import_pro_utils = require("@antdv/pro-utils");
var import_ant_design_vue = require("ant-design-vue");
var import_vue2 = require("vue");
var import_defaultSettings = require("../../defaultSettings");
var import_locales = require("../../locales");
var import_utils = require("../../utils/utils");
var import_BlockCheckbox = require("./BlockCheckbox");
var import_group = require("./icon/group");
var import_sub = require("./icon/sub");
var import_LayoutChange = require("./LayoutChange");
var import_RegionalChange = require("./RegionalChange");
var import_style = require("./style/index");
var import_ThemeColor = require("./ThemeColor");
const Body = (0, import_vue2.defineComponent)({
  name: "Body",
  props: {
    title: (0, import_pro_utils.stringType)(),
    prefixCls: (0, import_pro_utils.stringType)(),
    hashId: (0, import_pro_utils.stringType)()
  },
  setup(props, {
    slots
  }) {
    return () => {
      var _a;
      return (0, import_vue.createVNode)("div", {
        "style": {
          marginBlockEnd: `12px`
        }
      }, [(0, import_vue.createVNode)("h3", {
        "class": `${props.prefixCls}-body-title ${props.hashId}`.trim()
      }, [props.title]), (_a = slots.default) == null ? void 0 : _a.call(slots)]);
    };
  }
});
const settingDrawerProps = {
  defaultSettings: (0, import_pro_utils.objectType)(),
  settings: (0, import_pro_utils.objectType)(),
  collapse: (0, import_pro_utils.boolType)(),
  onCollapseChange: (0, import_pro_utils.funcType)(),
  getContainer: (0, import_pro_utils.anyType)(),
  hideHintAlert: (0, import_pro_utils.boolType)(),
  hideCopyButton: (0, import_pro_utils.boolType)(),
  enableDarkTheme: (0, import_pro_utils.boolType)(),
  prefixCls: (0, import_pro_utils.stringType)(),
  colorList: (0, import_pro_utils.oneOfType)([Boolean, Array]).def(void 0),
  onSettingChange: (0, import_pro_utils.funcType)(),
  pathname: (0, import_pro_utils.stringType)(),
  disableUrlParams: (0, import_pro_utils.boolType)().def(true),
  themeOnly: (0, import_pro_utils.boolType)()
};
function getDifferentSetting(state) {
  const stateObj = {};
  Object.keys(state).forEach((key) => {
    if (state[key] !== import_defaultSettings.defaultSettings[key] && key !== "collapse") {
      stateObj[key] = state[key];
    } else {
      stateObj[key] = void 0;
    }
    if (key.includes("Render")) {
      stateObj[key] = state[key] === false ? false : void 0;
    }
  });
  stateObj.menu = void 0;
  return stateObj;
}
function getFormatMessage() {
  const formatMessage = ({
    id
  }) => {
    const locales = (0, import_locales.gLocaleObject)();
    return locales[id];
  };
  return formatMessage;
}
function initState(urlParams, settings, onSettingChange) {
  if (!(0, import_pro_utils.isBrowser)()) return;
  const replaceSetting = {};
  Object.keys(urlParams).forEach((key) => {
    if (import_defaultSettings.defaultSettings[key] || import_defaultSettings.defaultSettings[key] === void 0) {
      if (key === "colorPrimary") {
        replaceSetting[key] = (0, import_utils.genStringToTheme)(urlParams[key]);
        return;
      }
      replaceSetting[key] = urlParams[key];
    }
  });
  const newSettings = (0, import_pro_provider.merge)({}, settings, replaceSetting);
  delete newSettings.menu;
  delete newSettings.title;
  delete newSettings.iconfontUrl;
  onSettingChange == null ? void 0 : onSettingChange(newSettings);
}
function getParamsFromUrl(urlParams, settings) {
  if (!(0, import_pro_utils.isBrowser)()) return import_defaultSettings.defaultSettings;
  return __spreadValues(__spreadValues(__spreadValues({}, import_defaultSettings.defaultSettings), settings || {}), urlParams);
}
function genCopySettingJson(settingState) {
  return JSON.stringify((0, import_pro_utils.omit)(__spreadProps(__spreadValues({}, settingState), {
    colorPrimary: settingState.colorPrimary
  }), ["colorWeak"]), null, 2);
}
const SettingDrawer = (0, import_vue2.defineComponent)({
  name: "SettingDrawer",
  props: settingDrawerProps,
  setup(props) {
    var _a;
    const firstRender = (0, import_vue2.ref)(true);
    const open = (0, import_vue2.ref)(props.collapse !== void 0 ? props.collapse : false);
    const [language, setLanguage] = (0, import_pro_utils.useState)((0, import_locales.getLanguage)());
    (0, import_vue2.watch)(() => props.collapse, () => {
      open.value = !!props.collapse;
    });
    const [urlParams, setUrlParams] = (0, import_pro_utils.useUrlSearchParams)({}, {
      disabled: (_a = props.disableUrlParams) != null ? _a : true
    });
    const [settingState, setSettingState] = (0, import_pro_utils.useMountMergeState)(() => getParamsFromUrl(urlParams, props.settings || props.defaultSettings), {
      value: (0, import_vue2.computed)(() => props.settings),
      onChange: props.onSettingChange
    });
    const onLanguageChange = () => {
      if (language.value !== (0, import_locales.getLanguage)()) {
        setLanguage((0, import_locales.getLanguage)());
      }
    };
    (0, import_vue2.onMounted)(() => {
      if (!(0, import_pro_utils.isBrowser)()) return;
      initState(getParamsFromUrl(urlParams, props.settings), settingState.value, setSettingState);
      window.document.addEventListener("languagechange", onLanguageChange, {
        passive: true
      });
    });
    (0, import_vue2.onUnmounted)(() => {
      window.document.removeEventListener("languagechange", onLanguageChange);
    });
    (0, import_vue2.watchEffect)(() => {
      if (!(0, import_pro_utils.isBrowser)()) return;
      if (props.disableUrlParams) return;
      if (firstRender.value) {
        firstRender.value = false;
        return;
      }
      const urlSearchParams = new URLSearchParams(window.location.search);
      const params = Object.fromEntries(urlSearchParams.entries());
      const diffParams = getDifferentSetting(__spreadValues(__spreadValues({}, params), settingState.value));
      delete diffParams.logo;
      delete diffParams.menu;
      delete diffParams.title;
      delete diffParams.iconfontUrl;
      delete diffParams.pwa;
      setUrlParams(diffParams);
    });
    const baseClassName = (0, import_vue2.computed)(() => `${props.prefixCls || "ant-pro"}-setting-drawer`);
    const {
      wrapSSR,
      hashId
    } = (0, import_style.useStyle)(baseClassName);
    return () => {
      const {
        hideHintAlert,
        hideCopyButton,
        colorList = [{
          key: "techBlue",
          color: "#1677FF"
        }, {
          key: "daybreak",
          color: "#1890ff"
        }, {
          key: "dust",
          color: "#F5222D"
        }, {
          key: "volcano",
          color: "#FA541C"
        }, {
          key: "sunset",
          color: "#FAAD14"
        }, {
          key: "cyan",
          color: "#13C2C2"
        }, {
          key: "green",
          color: "#52C41A"
        }, {
          key: "geekblue",
          color: "#2F54EB"
        }, {
          key: "purple",
          color: "#722ED1"
        }],
        getContainer,
        enableDarkTheme,
        themeOnly
      } = props;
      const {
        navTheme,
        colorPrimary,
        siderMenuType,
        layout,
        colorWeak
      } = settingState.value || {};
      const changeSetting = (key, value) => {
        const nextState = {};
        nextState[key] = value;
        if (key === "layout") {
          nextState.contentWidth = value === "top" ? "Fixed" : "Fluid";
        }
        if (key === "layout" && value !== "mix") {
          nextState.splitMenus = false;
        }
        if (key === "layout" && value === "mix") {
          nextState.navTheme = "light";
        }
        if (key === "colorWeak" && value === true) {
          const dom = document.querySelector("body");
          if (dom) {
            dom.dataset.prosettingdrawer = dom.style.filter;
            dom.style.filter = "invert(80%)";
          }
        }
        if (key === "colorWeak" && value === false) {
          const dom = document.querySelector("body");
          if (dom) {
            dom.style.filter = dom.dataset.prosettingdrawer || "none";
            delete dom.dataset.prosettingdrawer;
          }
        }
        delete nextState.menu;
        delete nextState.title;
        delete nextState.iconfontUrl;
        delete nextState.logo;
        delete nextState.pwa;
        setSettingState(__spreadValues(__spreadValues({}, settingState.value), nextState));
      };
      const formatMessage = getFormatMessage();
      return wrapSSR((0, import_vue.createVNode)(import_vue.Fragment, null, [(0, import_vue.createVNode)("div", {
        "class": `${baseClassName.value}-handle ${hashId.value}`.trim(),
        "onClick": () => {
          var _a2;
          open.value = !open.value;
          (_a2 = props.onCollapseChange) == null ? void 0 : _a2.call(props, open.value);
        },
        "style": {
          width: `48px`,
          height: `48px`
        }
      }, [open.value ? (0, import_vue.createVNode)(import_icons_vue.CloseOutlined, {
        "style": {
          color: "#fff",
          fontSize: `20px`
        }
      }, null) : (0, import_vue.createVNode)(import_icons_vue.SettingOutlined, {
        "style": {
          color: "#fff",
          fontSize: `20px`
        }
      }, null)]), (0, import_vue.createVNode)(import_ant_design_vue.Drawer, {
        "open": open.value,
        "width": 300,
        "onClose": () => {
          var _a2;
          open.value = false;
          (_a2 = props.onCollapseChange) == null ? void 0 : _a2.call(props, false);
        },
        "closable": false,
        "placement": "right",
        "getContainer": getContainer,
        "style": {
          zIndex: 999
        }
      }, {
        default: () => [(0, import_vue.createVNode)("div", {
          "class": `${baseClassName.value}-drawer-content ${hashId.value}`.trim()
        }, [(0, import_vue.createVNode)(Body, {
          "title": formatMessage({
            id: "app.setting.pagestyle",
            defaultMessage: "Page style setting"
          }),
          "hashId": hashId.value,
          "prefixCls": baseClassName.value
        }, {
          default: () => [(0, import_vue.createVNode)(import_BlockCheckbox.BlockCheckbox, {
            "hashId": hashId.value,
            "prefixCls": baseClassName.value,
            "list": [{
              key: "light",
              title: formatMessage({
                id: "app.setting.pagestyle.light",
                defaultMessage: "\u4EAE\u8272\u83DC\u5355\u98CE\u683C"
              })
            }, {
              key: "realDark",
              title: formatMessage({
                id: "app.setting.pagestyle.realdark",
                defaultMessage: "\u6697\u8272\u83DC\u5355\u98CE\u683C"
              })
            }].filter((item) => {
              if (item.key === "dark" && settingState.value.layout === "mix") return false;
              if (item.key === "realDark" && !enableDarkTheme) return false;
              return true;
            }),
            "value": navTheme,
            "configType": "theme",
            "key": "navTheme",
            "onChange": (value) => changeSetting("navTheme", value)
          }, null)]
        }), colorList !== false && (0, import_vue.createVNode)(Body, {
          "hashId": hashId.value,
          "title": formatMessage({
            id: "app.setting.themecolor",
            defaultMessage: "Theme color"
          }),
          "prefixCls": baseClassName.value
        }, {
          default: () => [(0, import_vue.createVNode)(import_ThemeColor.ThemeColor, {
            "hashId": hashId.value,
            "prefixCls": baseClassName.value,
            "colorList": colorList,
            "value": (0, import_utils.genStringToTheme)(colorPrimary),
            "formatMessage": formatMessage,
            "onChange": (color) => changeSetting("colorPrimary", color)
          }, null)]
        }), !themeOnly && (0, import_vue.createVNode)(import_vue.Fragment, null, [(0, import_vue.createVNode)(import_ant_design_vue.Divider, null, null), (0, import_vue.createVNode)(Body, {
          "hashId": hashId.value,
          "prefixCls": baseClassName.value,
          "title": formatMessage({
            id: "app.setting.navigationmode"
          })
        }, {
          default: () => [(0, import_vue.createVNode)(import_BlockCheckbox.BlockCheckbox, {
            "prefixCls": baseClassName.value,
            "value": layout,
            "key": "layout",
            "hashId": hashId.value,
            "configType": "layout",
            "list": [{
              key: "side",
              title: formatMessage({
                id: "app.setting.sidemenu"
              })
            }, {
              key: "top",
              title: formatMessage({
                id: "app.setting.topmenu"
              })
            }, {
              key: "mix",
              title: formatMessage({
                id: "app.setting.mixmenu"
              })
            }],
            "onChange": (value) => changeSetting("layout", value)
          }, null)]
        }), settingState.value.layout === "side" || settingState.value.layout === "mix" ? (0, import_vue.createVNode)(Body, {
          "hashId": hashId.value,
          "prefixCls": baseClassName.value,
          "title": formatMessage({
            id: "app.setting.sidermenutype"
          })
        }, {
          default: () => [(0, import_vue.createVNode)(import_BlockCheckbox.BlockCheckbox, {
            "prefixCls": baseClassName.value,
            "value": siderMenuType,
            "key": "siderMenuType",
            "hashId": hashId.value,
            "configType": "siderMenuType",
            "list": [{
              key: "sub",
              icon: (0, import_vue.createVNode)(import_sub.SubIcon, null, null),
              title: formatMessage({
                id: "app.setting.sidermenutype-sub"
              })
            }, {
              key: "group",
              icon: (0, import_vue.createVNode)(import_group.GroupIcon, null, null),
              title: formatMessage({
                id: "app.setting.sidermenutype-group"
              })
            }],
            "onChange": (value) => changeSetting("siderMenuType", value)
          }, null)]
        }) : null, (0, import_vue.createVNode)(import_LayoutChange.LayoutSetting, {
          "prefixCls": baseClassName.value,
          "hashId": hashId.value,
          "settings": settingState.value,
          "changeSetting": changeSetting
        }, null), (0, import_vue.createVNode)(import_ant_design_vue.Divider, null, null), (0, import_vue.createVNode)(Body, {
          "hashId": hashId.value,
          "prefixCls": baseClassName.value,
          "title": formatMessage({
            id: "app.setting.regionalsettings"
          })
        }, {
          default: () => [(0, import_vue.createVNode)(import_RegionalChange.RegionalSetting, {
            "hashId": hashId.value,
            "prefixCls": baseClassName.value,
            "settings": settingState.value,
            "changeSetting": changeSetting
          }, null)]
        }), (0, import_vue.createVNode)(import_ant_design_vue.Divider, null, null), (0, import_vue.createVNode)(Body, {
          "hashId": hashId.value,
          "prefixCls": baseClassName.value,
          "title": formatMessage({
            id: "app.setting.othersettings"
          })
        }, {
          default: () => [(0, import_vue.createVNode)(import_ant_design_vue.List, {
            "class": `${baseClassName.value}-list ${hashId.value}`.trim(),
            "split": false,
            "size": "small",
            "renderItem": import_LayoutChange.renderLayoutSettingItem,
            "dataSource": [{
              title: formatMessage({
                id: "app.setting.weakmode"
              }),
              action: (0, import_vue.createVNode)(import_ant_design_vue.Switch, {
                "size": "small",
                "class": "color-weak",
                "checked": !!colorWeak,
                "onChange": (checked) => {
                  changeSetting("colorWeak", checked);
                }
              }, null)
            }]
          }, null)]
        }), hideHintAlert && hideCopyButton ? null : (0, import_vue.createVNode)(import_ant_design_vue.Divider, null, null), hideHintAlert ? null : (0, import_vue.createVNode)(import_ant_design_vue.Alert, {
          "type": "warning",
          "message": formatMessage({
            id: "app.setting.production.hint"
          }),
          "icon": (0, import_vue.createVNode)(import_icons_vue.NotificationOutlined, null, null),
          "showIcon": true,
          "style": {
            marginBlockEnd: `16px`
          }
        }, null), hideCopyButton ? null : (0, import_vue.createVNode)(import_ant_design_vue.Button, {
          "block": true,
          "icon": (0, import_vue.createVNode)(import_icons_vue.CopyOutlined, null, null),
          "style": {
            marginBlockEnd: `24px`
          },
          "onClick": () => __async(this, null, function* () {
            try {
              yield navigator.clipboard.writeText(genCopySettingJson(settingState.value));
              import_ant_design_vue.message.success(formatMessage({
                id: "app.setting.copyinfo"
              }));
            } catch (error) {
            }
          })
        }, {
          default: () => [formatMessage({
            id: "app.setting.copy"
          })]
        })])])]
      })]));
    };
  }
});
