"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = AmityUiKitProvider;
var _reactNative = require("react-native");
var _reactRedux = require("react-redux");
var _AuthProvider = _interopRequireDefault(require("./AuthProvider"));
var _reactNativePaper = require("react-native-paper");
var _store = require("../stores/store");
var _ConfigProvider = require("./ConfigProvider");
var _color = require("../utils/color");
var _useValidateConfig = _interopRequireDefault(require("../../social/hooks/useValidateConfig"));
var _uikitConfig = _interopRequireDefault(require("../../../uikit.config.json"));
var _BehaviourProvider = require("../../social/providers/BehaviourProvider");
var _ExploreProvider = require("../../social/providers/ExploreProvider");
var _polished = require("polished");
var _AdEngineProvider = require("../../social/providers/AdEngineProvider");
var _BottomSheetComponent = _interopRequireDefault(require("../../social/components/BottomSheetComponent/BottomSheetComponent"));
var _Toast = _interopRequireDefault(require("../../social/components/Toast"));
var _reactQuery = require("@tanstack/react-query");
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _ErrorBoundary = require("../components/ErrorBoundary");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const queryClient = new _reactQuery.QueryClient();
function AmityUiKitProvider({
  userId,
  displayName,
  apiKey,
  apiRegion,
  apiEndpoint,
  children,
  authToken,
  configs,
  behaviour,
  fcmToken
}) {
  const colorScheme = (0, _reactNative.useColorScheme)();
  const SHADE_PERCENTAGES = [0.25, 0.4, 0.45, 0.6];
  const generateShades = (hexColor, isDarkTheme = false) => {
    // if the base color is the same as our design system colors, we need to return the shades of the design system colors
    // primary color
    if (hexColor.toLowerCase() === '#1054de') return ['#4A82F2', '#A9C4F9', '#D9E5FC', '#FFFFFF'];
    // secondary color
    if (hexColor.toLowerCase() === '#292b32' && !isDarkTheme) return ['#636878', '#898E9E', '#A5A9B5', '#EBECEF'];
    if (hexColor.toLowerCase() === '#ebecef' && isDarkTheme) return ['#A5A9B5', '#898E9E', '#40434E', '#292B32'];
    if (!hexColor) return Array(SHADE_PERCENTAGES.length).fill('');
    const hslColor = (0, _polished.parseToHsl)(hexColor);
    const shades = SHADE_PERCENTAGES.map(percentage => {
      return isDarkTheme ? (0, _polished.darken)(percentage, (0, _polished.hslToColorString)(hslColor)) : (0, _polished.lighten)(percentage, (0, _polished.hslToColorString)(hslColor));
    });
    return shades;
  };
  const isValidConfig = (0, _useValidateConfig.default)(configs);
  const configData = isValidConfig ? configs : _uikitConfig.default;
  const isDarkTheme = (configData === null || configData === void 0 ? void 0 : configData.preferred_theme) === 'dark' || (configData === null || configData === void 0 ? void 0 : configData.preferred_theme) === 'default' && colorScheme === 'dark';
  const themeColor = isDarkTheme ? configData.theme.dark : configData.theme.light;
  const primaryShades = generateShades(themeColor.primary_color, isDarkTheme);
  const secondaryShades = generateShades(themeColor.secondary_color, isDarkTheme);
  const globalTheme = {
    ..._reactNativePaper.DefaultTheme,
    isDarkTheme: isDarkTheme,
    colors: {
      ..._reactNativePaper.DefaultTheme.colors,
      primary: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.primary_color),
      primaryShade1: (0, _color.validateConfigColor)(primaryShades[0]),
      primaryShade2: (0, _color.validateConfigColor)(primaryShades[1]),
      primaryShade3: (0, _color.validateConfigColor)(primaryShades[2]),
      primaryShade4: (0, _color.validateConfigColor)(primaryShades[3]),
      secondary: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.secondary_color),
      secondaryShade1: (0, _color.validateConfigColor)(secondaryShades[0]),
      secondaryShade2: (0, _color.validateConfigColor)(secondaryShades[1]),
      secondaryShade3: (0, _color.validateConfigColor)(secondaryShades[2]),
      secondaryShade4: (0, _color.validateConfigColor)(secondaryShades[3]),
      background: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.background_color),
      backgroundShade1: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.background_shade1_color),
      base: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.base_color),
      baseShade1: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.base_shade1_color),
      baseShade2: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.base_shade2_color),
      baseShade3: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.base_shade3_color),
      baseShade4: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.base_shade4_color),
      alert: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.alert_color),
      live: (0, _color.validateConfigColor)(themeColor === null || themeColor === void 0 ? void 0 : themeColor.live_color),
      transparentBlack: 'rgba(0,0,0,0.5)',
      black: '#000000',
      white: '#FFFFFF'
    }
  };
  return /*#__PURE__*/React.createElement(_ErrorBoundary.ErrorBoundary, null, /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaProvider, null, /*#__PURE__*/React.createElement(_reactQuery.QueryClientProvider, {
    client: queryClient
  }, /*#__PURE__*/React.createElement(_reactRedux.Provider, {
    store: _store.store,
    context: _store.AmityUIKitReduxContext
  }, /*#__PURE__*/React.createElement(_AuthProvider.default, {
    userId: userId,
    displayName: displayName || userId,
    apiKey: apiKey,
    apiRegion: apiRegion,
    apiEndpoint: apiEndpoint,
    authToken: authToken,
    fcmToken: fcmToken
  }, /*#__PURE__*/React.createElement(_AdEngineProvider.AdEngineProvider, null, /*#__PURE__*/React.createElement(_ConfigProvider.ConfigProvider, {
    configs: configData
  }, /*#__PURE__*/React.createElement(_BehaviourProvider.BehaviourProvider, {
    behaviour: behaviour
  }, /*#__PURE__*/React.createElement(_ExploreProvider.ExploreProvider, null, /*#__PURE__*/React.createElement(_reactNativePaper.PaperProvider, {
    theme: globalTheme
  }, children, /*#__PURE__*/React.createElement(_BottomSheetComponent.default, null), /*#__PURE__*/React.createElement(_Toast.default, null)))))))))));
}
//# sourceMappingURL=AmityUIKitProvider.js.map