"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "useThemeProps", {
  enumerable: true,
  get: function () {
    return _useProps.useThemeProps;
  }
});
Object.defineProperty(exports, "usePropsResolution", {
  enumerable: true,
  get: function () {
    return _usePropsResolution.usePropsResolution;
  }
});
exports.useComponentThemePropsResolution = void 0;

var _useProps = require("./useProps");

var _usePropsResolution = require("./usePropsResolution");

var _lodash = _interopRequireDefault(require("lodash.merge"));

var _getStyledComponentAndObjects = require("../../utils/getStyledComponentAndObjects");

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

var _tools = require("../../theme/tools");

var _core = require("../../core");

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

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

const useResolvedFactoryProps = (styleObj, incomingProps, colorMode, theme, componentTheme, incomingInternalThemeProps, incomingStateProps) => {
  const providerId = (0, _NativeBaseContext.useNativeBaseConfig)('NativeBase').providerId;
  const resolvedPropsWithStateProps = (0, _usePropsResolution.usePropsResolutionWithComponentTheme)(componentTheme, incomingProps, theme, {});
  resolvedPropsWithStateProps.stateProps = (0, _lodash.default)({}, resolvedPropsWithStateProps === null || resolvedPropsWithStateProps === void 0 ? void 0 : resolvedPropsWithStateProps.stateProps, incomingStateProps);
  styleObj.styleFromProps = (0, _lodash.default)({}, styleObj.styleFromProps, incomingInternalThemeProps);
  const stateStyleFromProps = (0, _tools.omitUndefined)(styleObj === null || styleObj === void 0 ? void 0 : styleObj.stateStyleFromProps);
  const resolvedProps = (0, _usePropsResolution.mergeFinalResolvedProps)(componentTheme, styleObj, incomingProps, '', stateStyleFromProps, resolvedPropsWithStateProps, {
    component: '',
    theme,
    providerId,
    colorMode,
    ignoredProps: {},
    stateProps: {},
    notResolveThemeProps: false
  });
  return resolvedProps;
};

const getModiefiedIncomingProps = incomingProps => {
  const incomingInternalThemeProps = _lodash.default.apply({}, incomingProps === null || incomingProps === void 0 ? void 0 : incomingProps.INTERNAL_themeStyle);

  const incomingStateProps = incomingProps === null || incomingProps === void 0 ? void 0 : incomingProps.stateProps;
  const modifiedIncomingProps = incomingProps;
  modifiedIncomingProps === null || modifiedIncomingProps === void 0 ? true : delete modifiedIncomingProps.INTERNAL_themeStyle;
  modifiedIncomingProps === null || modifiedIncomingProps === void 0 ? true : delete modifiedIncomingProps.stateProps;
  return {
    modifiedIncomingProps,
    incomingInternalThemeProps,
    incomingStateProps
  };
};

const useComponentThemePropsResolution = (componentTheme, incomingProps, theme) => {
  const {
    colorMode
  } = (0, _core.useColorMode)();
  const {
    modifiedIncomingProps,
    incomingInternalThemeProps,
    incomingStateProps
  } = getModiefiedIncomingProps(incomingProps);
  const styleObj = (0, _getStyledComponentAndObjects.getStyledObject)(theme, '', componentTheme, {
    platform: _reactNative.Platform.OS,
    colorMode: colorMode
  }, (0, _lodash.default)({}, modifiedIncomingProps), true);
  const resolvedProps = useResolvedFactoryProps(styleObj, (0, _lodash.default)({}, styleObj === null || styleObj === void 0 ? void 0 : styleObj.unResolvedProps, styleObj === null || styleObj === void 0 ? void 0 : styleObj.restDefaultProps, modifiedIncomingProps), colorMode, theme, componentTheme, incomingInternalThemeProps, incomingStateProps);
  return resolvedProps;
};

exports.useComponentThemePropsResolution = useComponentThemePropsResolution;
//# sourceMappingURL=index.js.map