"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useStyledSystemPropsResolver = void 0;

var _styledSystem = require("../theme/styled-system");

var _useTheme = require("./useTheme");

var _react = _interopRequireDefault(require("react"));

var _NativeBaseContext = require("../core/NativeBaseContext");

var _useResponsiveQuery = require("../utils/useResponsiveQuery");

var _stableHash = _interopRequireDefault(require("stable-hash"));

var _propsFlattener = require("./useThemeProps/propsFlattener");

var _reactNative = require("react-native");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* eslint-disable react-hooks/exhaustive-deps */
//@ts-ignore
const getStyledSystemPropsAndRestProps = props => {
  const styledSystemProps = {};
  const restProps = {};

  for (const key in props) {
    if (key in _styledSystem.propConfig) {
      styledSystemProps[key] = props[key];
    } else {
      restProps[key] = props[key];
    }
  }

  return {
    styledSystemProps,
    restProps
  };
};

const useStyledSystemPropsResolver = ({
  style: propStyle,
  debug,
  ...props
}) => {
  // console.time("PROP_CONFIG");
  const theme = (0, _useTheme.useTheme)();
  const {
    currentBreakpoint,
    config
  } = (0, _NativeBaseContext.useNativeBaseConfig)('makeStyledComponent');
  const strictMode = config.strictMode;
  const {
    getResponsiveStyles
  } = (0, _useResponsiveQuery.useResponsiveQuery)(); // console.timeEnd("PROP_CONFIG");

  const {
    styledSystemProps,
    restProps
  } = getStyledSystemPropsAndRestProps(props); // console.log('** use prop resolution ***', props, getResponsiveStyles);
  // console.log('useStyledSystemPropsResolver', restProps);

  const {
    style,
    dataSet
  } = _react.default.useMemo(() => {
    const resolvedStyle = (0, _propsFlattener.resolvePropsToStyle)(styledSystemProps, propStyle, theme, _reactNative.Platform.OS, debug, currentBreakpoint, strictMode, getResponsiveStyles, restProps.INTERNAL_themeStyle); // console.log(
    //   StyleSheet.flatten(resolvedStyle.style),
    //   styledSystemProps,
    //   '******'
    // );

    return resolvedStyle; // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [// eslint-disable-next-line react-hooks/exhaustive-deps
  (0, _stableHash.default)(styledSystemProps), theme, currentBreakpoint, debug, strictMode, (0, _stableHash.default)(propStyle), getResponsiveStyles, (0, _stableHash.default)(props)]); // if (process.env.NODE_ENV === "development" && debug) {
  //   /* eslint-disable-next-line */
  //   console.log("style,resprops", currentBreakpoint);
  // }
  // console.log('** use prop resolution 2', restProps);


  restProps.dataSet = dataSet; // console.timeEnd("useStyledSystemPropsResolver");

  return [style, restProps];
};

exports.useStyledSystemPropsResolver = useStyledSystemPropsResolver;
//# sourceMappingURL=useStyledSystemPropsResolver.js.map