"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _getCleanUri = _interopRequireDefault(require("../../util/get-clean-uri"));
var _getResizedImage = _interopRequireDefault(require("../../util/get-resized-image"));
var _index = _interopRequireDefault(require("../gradient/index.native"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const styles = _reactNative.StyleSheet.create({
  image: {
    width: '100%',
    height: '100%'
  },
  gradient: {
    flex: 1
  }
});
const ImageBackground = ({
  source,
  gradient,
  gradientStyle,
  style,
  testID = 'image-background',
  ...props
}) => {
  let uri = source && source.uri;
  if (uri) {
    const {
      width: _width,
      height: _height,
      resizeMode
    } = props;
    const {
      width,
      height
    } = _reactNative.StyleSheet.flatten([{
      width: _width,
      height: _height
    }, style]);
    const maxHeight = typeof height === 'number' ? height : undefined;
    const maxWidth = typeof width === 'number' ? width : undefined;
    uri = (0, _getResizedImage.default)((0, _getCleanUri.default)(uri), {
      maxHeight,
      maxWidth,
      resizeMode
    });
  }
  const resizedSource = uri && {
    uri
  } || source;
  if (gradient) {
    const {
      children,
      ...remainingProps
    } = props;
    const _style = [styles.gradient];
    if (gradientStyle) {
      _style.push(gradientStyle);
    }
    return /*#__PURE__*/_react.default.createElement(_reactNative.ImageBackground, _extends({}, remainingProps, {
      source: resizedSource,
      style: [styles.image, style],
      testID: testID
    }), /*#__PURE__*/_react.default.createElement(_index.default, {
      testID: `${testID}-gradient`,
      colors: gradient,
      style: _style
    }, children));
  }
  return /*#__PURE__*/_react.default.createElement(_reactNative.ImageBackground, _extends({}, props, {
    source: resizedSource,
    style: [styles.image, style],
    testID: testID
  }));
};
var _default = exports.default = ImageBackground;
//# sourceMappingURL=index.native.js.map