import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import useEngineContext from "../../hooks/useEngineContext.js";
import ConfigProvider$1 from "../config-provider/index.js";
import VariablesProvider from "../dataSourceComponents/provider/variables/VariablesProvider.js";
import PisellConfigProvider from "../pisell-config-provider/index.js";
import { getThemeConfig } from "../../theme/tokens.js";
import React, { useEffect, useMemo } from "react";
import { App } from "antd";
import zhCN from "antd/es/locale/zh_CN";
import { LocaleProvider, LocalizationProvider, ThemeProvider, createTheme } from "@pisell/date-picker";
import { AdapterDayjs } from "@pisell/date-picker/es/AdapterDayjs";
import enUS from "antd/es/locale/en_US";
import zhTW from "antd/es/locale/zh_TW";
import zhHK from "antd/es/locale/zh_HK";
import jaJP from "antd/es/locale/ja_JP";
import ptPT from "antd/es/locale/pt_PT";
//#region src/components/page/index.tsx
const _excluded = [
	"children",
	"style",
	"className",
	"locale",
	"variablesConfig",
	"isRenderPisellConfigProvider"
];
const localMap = {
	"zh-TW": zhTW,
	"zh-CN": zhCN,
	"zh-HK": zhHK,
	"en-US": enUS,
	en: enUS,
	"ja": jaJP,
	"pt": ptPT
};
const localeDateMap = {
	"en-US": { adapterLocale: "en" },
	en: { adapterLocale: "en" },
	"zh-TW": { adapterLocale: "zh-tw" },
	"zh-HK": { adapterLocale: "zh-tw" },
	"zh-CN": { adapterLocale: "zh-cn" },
	"ja": { adapterLocale: "ja" },
	"pt": { adapterLocale: "pt" }
};
const Page = (props) => {
	var _context$appHelper, _context$engine, _localeDateMap, _context$engine2;
	const { children, style, className, locale: propsLocale, variablesConfig, isRenderPisellConfigProvider = true } = props, others = _objectWithoutProperties(props, _excluded);
	const context = useEngineContext();
	const { platform, themeColor } = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.constants) || {};
	const 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";
	const theme = useMemo(() => {
		if (props === null || props === void 0 ? void 0 : props.theme) {
			var _props$theme;
			return _objectSpread2(_objectSpread2({}, props.theme), {}, { token: _objectSpread2(_objectSpread2({}, props.theme.token), {}, { 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 getThemeConfig(themeColor);
	}, [themeColor, props === null || props === void 0 ? void 0 : props.theme]);
	const datePickerTheme = useMemo(() => {
		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]);
	const PisellConfigProvid = isRenderPisellConfigProvider ? PisellConfigProvider : React.Fragment;
	useEffect(() => {
		document.body.id = "body";
	}, []);
	return /* @__PURE__ */ React.createElement(ConfigProvider$1, _objectSpread2(_objectSpread2({}, others), {}, {
		locale: localMap[locale],
		prefixCls: props.prefixCls || "pisell-lowcode",
		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 } }, /* @__PURE__ */ React.createElement(PisellConfigProvid, { 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) || {},
		config: variablesConfig
	}, /* @__PURE__ */ React.createElement("div", {
		style: _objectSpread2(_objectSpread2({}, style), {}, { "--theme-color": themeColor || "#5D3F9F" }),
		className
	}, children))))))));
};
//#endregion
export { Page as default };
