import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import { IconProvider } from '@zarm-design/icons';
import * as React from 'react';
import defaultLocaleData from './locale/zh_CN';
import setCssVars from './setCssVars';
import setPrimaryColor from './setPrimaryColor';
import setTheme from './setTheme';
export var defaultConfig = {
  prefixCls: 'za',
  locale: defaultLocaleData,
  theme: 'light',
  safeArea: true,
  cssVars: {},
  mountContainer: function mountContainer() {
    return document.body;
  },
  scrollContainer: function scrollContainer() {
    return window;
  }
};
export var ConfigContext = /*#__PURE__*/React.createContext(defaultConfig);
var runtimeConfigContext = defaultConfig;

var changeRuntimeConfigContext = function changeRuntimeConfigContext(props) {
  runtimeConfigContext = props;
};

export var getRuntimeConfig = function getRuntimeConfig() {
  return runtimeConfigContext;
};

var ConfigProvider = function ConfigProvider(props) {
  var children = props.children,
      cssVars = props.cssVars,
      primaryColor = props.primaryColor,
      theme = props.theme,
      rest = _objectWithoutProperties(props, ["children", "cssVars", "primaryColor", "theme"]);

  changeRuntimeConfigContext(props);
  React.useEffect(function () {
    primaryColor && setPrimaryColor(primaryColor);
  }, [primaryColor]);
  React.useEffect(function () {
    theme && setTheme(theme);
  }, [theme]);
  var newChildren = setCssVars(children, cssVars);
  return /*#__PURE__*/React.createElement(ConfigContext.Provider, {
    value: rest
  }, /*#__PURE__*/React.createElement(IconProvider, {
    value: {
      prefixCls: rest.prefixCls
    }
  }, React.Children.only(newChildren)));
};

export var RuntimeConfigProvider = function RuntimeConfigProvider(_ref) {
  var children = _ref.children;
  var props = React.useRef(runtimeConfigContext);
  React.useEffect(function () {
    props.current = runtimeConfigContext;
  }, [runtimeConfigContext]);
  return /*#__PURE__*/React.createElement(ConfigProvider, props === null || props === void 0 ? void 0 : props.current, children);
};
ConfigProvider.displayName = 'ConfigProvider';
ConfigProvider.defaultProps = defaultConfig;
export default ConfigProvider;