function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["children", "style", "className", "locale"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo } from 'react';
import ConfigProvider from "../config-provider";
import { AdapterDayjs } from '@pisell/date-picker/es/AdapterDayjs';
import VariablesProvider from "../dataSourceComponents/provider/variables/VariablesProvider";
import { LocalizationProvider, createTheme, ThemeProvider, LocaleProvider } from '@pisell/date-picker';
import { App } from 'antd';
import enUS from 'antd/locale/en_US';
import zhCN from 'antd/locale/zh_CN';
import zhTW from 'antd/locale/zh_TW';
import zhHK from 'antd/locale/zh_HK';
import PisellConfigProvider from "../pisell-config-provider";
import useEngineContext from "../../hooks/useEngineContext";
var localMap = {
  'zh-TW': zhTW,
  'zh-CN': zhCN,
  'zh-HK': zhHK,
  'en-US': enUS,
  en: enUS
};
var localeDateMap = {
  'en-US': {
    adapterLocale: 'en'
  },
  en: {
    adapterLocale: 'en'
  },
  'zh-TW': {
    adapterLocale: 'zh-tw'
  },
  'zh-HK': {
    adapterLocale: 'zh-tw'
  },
  'zh-CN': {
    adapterLocale: 'zh-cn'
  }
};
var Page = function Page(props) {
  var _context$appHelper, _context$engine, _context$engine$props, _localeDateMap;
  var children = props.children,
    style = props.style,
    className = props.className,
    propsLocale = props.locale,
    others = _objectWithoutProperties(props, _excluded);
  var context = useEngineContext();
  var _ref = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.constants) || {},
    platform = _ref.platform,
    themeColor = _ref.themeColor;
  var locale = propsLocale || (context === null || context === void 0 ? void 0 : (_context$engine = context.engine) === null || _context$engine === void 0 ? void 0 : (_context$engine$props = _context$engine.props) === null || _context$engine$props === void 0 ? void 0 : _context$engine$props.locale) || 'en';
  var theme = useMemo(function () {
    if (props !== null && props !== void 0 && props.theme) {
      var _props$theme, _props$theme$token;
      return _objectSpread(_objectSpread({}, props.theme), {}, {
        // cssVar: { key: 'app' },
        token: _objectSpread(_objectSpread({}, props.theme.token), {}, {
          // 外部透传主题时，如果没有传入colorPrimary 默认使用主项目内主题色
          colorPrimary: (props === null || props === void 0 ? void 0 : (_props$theme = props.theme) === null || _props$theme === void 0 ? void 0 : (_props$theme$token = _props$theme.token) === null || _props$theme$token === void 0 ? void 0 : _props$theme$token.colorPrimary) || themeColor || '#7F56D9'
        })
      });
    }
    return {
      // cssVar: { key: 'app' },
      components: {
        Table: {
          colorFillContent: '#EAECF0',
          colorFillSecondary: '#F2F4F7',
          colorBorderSecondary: '#EAECF0',
          colorFillAlter: '#F9FAFB',
          controlItemBgHover: '#F9FAFB',
          colorTextHeading: '#475467',
          colorTextDescription: '#667085',
          colorText: '#101828',
          controlHeight: 32,
          padding: 24,
          margin: 16
        },
        Message: {
          contentBg: '#101828'
        },
        Button: {
          borderRadiusSM: 6,
          borderRadiusLG: 9,
          borderRadius: 8,
          controlHeight: 36,
          colorBgContainerDisabled: '#F2F4F7',
          colorBgTextHover: '#F9FAFB',
          colorBorder: '#D0D5DD',
          colorError: '#D92D20',
          colorErrorActive: '#D92D20',
          colorErrorHover: '#B42318',
          colorErrorBg: '#FEF3F2',
          colorErrorBorderHover: '#FDA29B',
          colorErrorOutline: 'rgba(217, 45, 32, 0.06)',
          colorLink: '#175CD3',
          colorLinkActive: '#194185',
          colorLinkHover: '#1849A9',
          // colorPrimaryActive: '#7f56d9',
          // colorPrimaryBorder: '#E9D7FE',
          colorText: '#344054',
          colorTextDisabled: '#D0D5DD',
          colorTextLightSolid: '#fff',
          colorBgTextActive: '#D0D5DD',
          controlOutline: 'rgba(127, 86, 217, 0.04)',
          controlTmpOutline: '#F9FAFB',
          paddingContentHorizontal: 14,
          marginXS: 8
        },
        Divider: {
          colorSplit: '#EAECF0'
        },
        Breadcrumb: {
          itemColor: '#475467',
          colorTextDescription: '#475467',
          // lastItemColor: '#6941C6',
          separatorMargin: 12,
          separatorColor: '#D0D5DD',
          linkHoverColor: '#1D2939',
          linkColor: '#475467',
          colorBgTextHover: '#F9FAFB',
          paddingXXS: 8
        },
        Dropdown: {
          borderRadiusLG: 8,
          // "boxShadowPopoverArrow": "2px 2px 5px rgba(0, 0, 0, 0.05)",
          controlHeight: 42,
          fontSize: 14
        },
        DatePicker: {
          borderRadius: 8,
          colorTextPlaceholder: '#667085',
          colorIcon: '#667085',
          colorTextQuaternary: '#D0D5DD',
          colorBgContainerDisabled: '#F9FAFB',
          colorTextDisabled: '#98A2B3'
        },
        Input: {
          fontSizeIcon: 16,
          addonBg: '#fff'
          // "lineHeight": 1
        },

        Select: {
          fontSizeIcon: 16
          // "lineHeight": 1
        }
      },

      token: {
        colorPrimary: themeColor || '#7F56D9',
        // colorPrimaryBg: '#F9F5FF',
        // colorPrimaryBgHover: '#F4EBFF',
        // colorPrimaryBorder: '#E9D7FE',
        // colorPrimaryBorderHover: '#D6BBFB',
        // colorPrimaryHover: '#6941C6',
        // colorPrimaryActive: '#53389E',
        // colorPrimaryTextHover: '#53389E',
        // colorPrimaryText: '#6941C6',
        // colorPrimaryTextActive: '#42307D',
        colorSuccess: '#079455',
        colorSuccessBg: '#ECFDF3',
        colorSuccessBgHover: '#DCFAE6',
        colorSuccessBorder: '#ABEFC6',
        colorSuccessBorderHover: '#75E0A7',
        colorSuccessHover: '#067647',
        colorSuccessText: '#067647',
        colorSuccessActive: '#085D3A',
        colorSuccessTextHover: '#085D3A',
        colorSuccessTextActive: '#074D31',
        colorWarning: '#dc6803',
        colorWarningBg: '#FFFAEB',
        colorWarningBgHover: '#FEF0C7',
        colorWarningBorder: '#FEDF89',
        colorWarningBorderHover: '#FEC84B',
        colorWarningHover: '#B54708',
        colorWarningText: '#B54708',
        colorWarningActive: '#93370D',
        colorWarningTextHover: '#93370D',
        colorWarningTextActive: '#7A2E0E',
        colorError: '#d92d20',
        colorErrorBg: '#FEF3F2',
        colorErrorBgHover: '#FEE4E2',
        colorErrorBorder: '#FECDCA',
        colorErrorBorderHover: '#FDA29B',
        colorErrorHover: '#B42318',
        colorErrorText: '#B42318',
        colorErrorActive: '#912018',
        colorErrorTextHover: '#912018',
        colorErrorTextActive: '#7A271A',
        colorInfo: '#1570ef',
        colorInfoBg: '#EFF8FF',
        colorInfoBgHover: '#D1E9FF',
        colorInfoBorder: '#B2DDFF',
        colorInfoBorderHover: '#84CAFF',
        colorInfoHover: '#175CD3',
        colorInfoText: '#175CD3',
        colorInfoActive: '#1849A9',
        colorInfoTextHover: '#1849A9',
        colorInfoTextActive: '#194185',
        colorText: '#101828',
        colorTextSecondary: '#475467',
        colorTextTertiary: '#667085',
        colorTextQuaternary: '#D0D5DD',
        colorBorder: '#D0D5DD',
        colorBorderSecondary: '#EAECF0',
        colorFill: '#D0D5DD',
        colorFillSecondary: '#EAECF0',
        colorFillTertiary: '#F2F4F7',
        colorFillQuaternary: '#F9FAFB',
        colorBgLayout: '#F2F4F7',
        colorBgSpotlight: '#101828',
        colorBgMask: 'rgba(0, 0, 0, 0.5)',
        wireframe: false,
        borderRadius: 8
      }
    };
  }, [platform, themeColor, props === null || props === void 0 ? void 0 : props.theme]);
  var datePickerTheme = useMemo(function () {
    var _theme$token;
    return createTheme({
      palette: {
        primary: {
          main: ((_theme$token = theme.token) === null || _theme$token === void 0 ? void 0 : _theme$token.colorPrimary) || '#7F56D9'
        }
      }
    });
  }, [platform, themeColor]);
  return /*#__PURE__*/React.createElement(ConfigProvider, _extends({}, others, {
    locale: localMap[locale],
    prefixCls: props.prefixCls || 'pisell-lowcode',
    theme: theme
  }), /*#__PURE__*/React.createElement(App, {
    component: false,
    message: {
      maxCount: 1
    }
  }, /*#__PURE__*/React.createElement(LocalizationProvider, {
    dateAdapter: AdapterDayjs,
    adapterLocale: (localeDateMap === null || localeDateMap === void 0 ? void 0 : (_localeDateMap = localeDateMap[locale]) === null || _localeDateMap === void 0 ? void 0 : _localeDateMap.adapterLocale) || 'en'
  }, /*#__PURE__*/React.createElement(ThemeProvider, {
    theme: datePickerTheme
  }, /*#__PURE__*/React.createElement(LocaleProvider, {
    value: {
      locale: locale
    }
  }, /*#__PURE__*/React.createElement(PisellConfigProvider, {
    locale: locale
  }, /*#__PURE__*/React.createElement(VariablesProvider, null, /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, style), {}, {
      '--theme-color': themeColor || '#7F56D9'
    }),
    className: className
  }, children))))))));
};
export default Page;