function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { memo, forwardRef } from 'react';
import { View } from 'react-native';
import { usePropsResolution } from '../../../hooks/useThemeProps';
import { getColor } from '../../../theme';
import { useTheme } from '../../../hooks/useTheme';
import { makeStyledComponent } from '../../../utils/makeStyledComponent';
import { wrapStringChild } from '../../../utils/wrapStringChild';
import { useSafeArea } from '../../../hooks/useSafeArea';
import { useNativeBaseConfig } from '../../../core/NativeBaseContext';
const StyledBox = makeStyledComponent(View);
let MemoizedGradient;

const safeAreaPropsExists = props => {
  if (props.safeArea || props.safeAreaX || props.safeAreaY || props.safeAreaTop || props.safeAreaBottom || props.safeAreaLeft || props.safeAreaRight) {
    return true;
  }

  return false;
};

const gradientPropExists = props => {
  var _props$bg, _props$background, _props$bgColor, _props$backgroundColo;

  if ((_props$bg = props.bg) !== null && _props$bg !== void 0 && _props$bg.linearGradient || (_props$background = props.background) !== null && _props$background !== void 0 && _props$background.linearGradient || (_props$bgColor = props.bgColor) !== null && _props$bgColor !== void 0 && _props$bgColor.linearGradient || (_props$backgroundColo = props.backgroundColor) !== null && _props$backgroundColo !== void 0 && _props$backgroundColo.linearGradient) {
    return true;
  }

  return false;
};

const GradientBox = /*#__PURE__*/forwardRef(({
  children,
  _text,
  ...props
}, ref) => {
  var _props$bg2, _props$background2, _props$bgColor2, _props$backgroundColo2, _lgrad$colors, _useNativeBaseConfig$;

  const theme = useTheme(); // return null;

  const lgrad = ((_props$bg2 = props.bg) === null || _props$bg2 === void 0 ? void 0 : _props$bg2.linearGradient) || ((_props$background2 = props.background) === null || _props$background2 === void 0 ? void 0 : _props$background2.linearGradient) || ((_props$bgColor2 = props.bgColor) === null || _props$bgColor2 === void 0 ? void 0 : _props$bgColor2.linearGradient) || ((_props$backgroundColo2 = props.backgroundColor) === null || _props$backgroundColo2 === void 0 ? void 0 : _props$backgroundColo2.linearGradient);
  lgrad.colors = (_lgrad$colors = lgrad.colors) === null || _lgrad$colors === void 0 ? void 0 : _lgrad$colors.map(color => {
    return getColor(color, theme.colors, theme);
  });
  let startObj = {
    x: 0,
    y: 0
  };
  let endObj = {
    x: 0,
    y: 1
  };

  if (lgrad.start && lgrad.start.length === 2) {
    startObj = {
      x: lgrad.start[0],
      y: lgrad.start[1]
    };
  }

  if (lgrad.end && lgrad.end.length === 2) {
    endObj = {
      x: lgrad.end[0],
      y: lgrad.end[1]
    };
  }

  let Gradient = (_useNativeBaseConfig$ = useNativeBaseConfig('NativeBaseConfigProvider').config.dependencies) === null || _useNativeBaseConfig$ === void 0 ? void 0 : _useNativeBaseConfig$['linear-gradient'];

  if (!MemoizedGradient) {
    MemoizedGradient = makeStyledComponent(Gradient);
  } // const backgroundColorProps = [
  //   'bg',
  //   'bgColor',
  //   'background',
  //   'backgroundColor',
  // ];
  // backgroundColorProps.forEach((backgroundColorProp) => {
  //   if (backgroundColorProp in safeAreaProps)
  //     delete safeAreaProps[backgroundColorProp];
  // });
  // return 'hello';


  return /*#__PURE__*/React.createElement(MemoizedGradient, _extends({
    ref: ref
  }, props, {
    colors: lgrad.colors,
    start: startObj,
    end: endObj,
    locations: lgrad.locations
  }), wrapStringChild(children, _text));
}); // const getContext = () => {
//   // const context = React.useContext(Context);
//   // return context;
//   console.log(window['currentBreakpoint'], 'hello current breakpoint');
// };

const Box = ({
  children,
  ...props
}, ref) => {
  const {
    _text,
    ...resolvedProps
  } = usePropsResolution('Box', props); // console.log(resolvedProps, props, 'resolved props here');

  if (safeAreaPropsExists(props)) {
    return /*#__PURE__*/React.createElement(BoxComponentWithSafeArea, _extends({}, resolvedProps, {
      _text: _text,
      ref: ref
    }), children);
  } else {
    return /*#__PURE__*/React.createElement(BoxComponentWithoutSafeArea, _extends({}, resolvedProps, {
      _text: _text,
      ref: ref
    }), children);
  } // return (
  //   <StyledBox ref={ref} {...safeAreaProps}>
  //     {/* {React.Children.map(children, (child) => {
  //       return typeof child === 'string' ||
  //         typeof child === 'number' ||
  //         (child?.type === React.Fragment &&
  //           (typeof child.props?.children === 'string' ||
  //             typeof child.props?.children === 'number')) ? (
  //         <Text {..._text}>{child}</Text>
  //       ) : (
  //         child
  //       );
  //     })} */}
  //     {wrapStringChild(children, _text)}
  //   </StyledBox>
  // );

};

const BoxComponentWithSafeArea = /*#__PURE__*/forwardRef(({
  children,
  _text,
  ...props
}, ref) => {
  const safeAreaProps = useSafeArea(props);

  if (gradientPropExists(props) && GradientBox) {
    return /*#__PURE__*/React.createElement(GradientBox, _extends({}, props, safeAreaProps, {
      _text: _text,
      ref: ref
    }), children);
  } else {
    return /*#__PURE__*/React.createElement(StyledBox, _extends({
      ref: ref
    }, safeAreaProps), wrapStringChild(children, _text));
  }
});
const BoxComponentWithoutSafeArea = /*#__PURE__*/forwardRef(({
  children,
  _text,
  ...props
}, ref) => {
  if (gradientPropExists(props) && GradientBox) {
    return /*#__PURE__*/React.createElement(GradientBox, _extends({}, props, {
      ref: ref,
      _text: _text
    }), children);
  } else {
    return /*#__PURE__*/React.createElement(StyledBox, _extends({
      ref: ref
    }, props), wrapStringChild(children, _text));
  }
});
export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(Box));
//# sourceMappingURL=index.js.map