function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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/es/locale/en_US';
import zhCN from 'antd/es/locale/zh_CN';
import zhTW from 'antd/es/locale/zh_TW';
import zhHK from 'antd/es/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, _localeDateMap, _context$engine2;
  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 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || 'en';
  var theme = useMemo(function () {
    if (props !== null && props !== void 0 && props.theme) {
      var _props$theme;
      return _objectSpread(_objectSpread({}, props.theme), {}, {
        // cssVar: { key: 'app' },
        token: _objectSpread(_objectSpread({}, props.theme.token), {}, {
          // 外部透传主题时，如果没有传入colorPrimary 默认使用主项目内主题色
          colorPrimary: (props === null || props === void 0 || (_props$theme = props.theme) === null || _props$theme === void 0 || (_props$theme = _props$theme.token) === null || _props$theme === void 0 ? void 0 : _props$theme.colorPrimary) || themeColor || '#5D3F9F'
        })
      });
    }
    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: '#7F56DA',
          colorLinkActive: '#5F3DA8',
          colorLinkHover: '#6D48C4',
          // colorPrimaryActive: '#5D3F9F',
          // 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
        },
        Menu: {
          subMenuItemSelectedColor: "#9976e3"
        }
      },
      token: {
        colorPrimary: themeColor || '#5D3F9F',
        colorPrimaryBg: '#eee5ff',
        colorPrimaryBgHover: '#e4d9fc',
        colorPrimaryBorder: '#d4c3f7',
        colorSuccess: '#5f9e3f',
        colorInfo: '#5d3f9f',
        colorError: '#f5222d',
        colorSuccessBg: '#e5fcd9',
        colorSuccessBgHover: '#d5f7c3',
        // 链接色
        colorLink: '#7F56DA',
        colorLinkActive: '#5F3DA8',
        colorLinkHover: '#6D48C4',
        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) || '#5D3F9F'
        }
      }
    });
  }, [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 || (_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, {
    variables: ((_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.variables) || {}
  }, /*#__PURE__*/React.createElement("div", {
    style: _objectSpread(_objectSpread({}, style), {}, {
      '--theme-color': themeColor || '#5D3F9F'
    }),
    className: className
  }, children))))))));
};
export default Page;