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); }
import React from 'react';
import { ImageBackground as ImageBackgroundBase, StyleSheet } from 'react-native';
import getCleanUri from '../../util/get-clean-uri';
import getResizedImage from '../../util/get-resized-image';
import Gradient from '../gradient/index.native';
const styles = 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
    } = StyleSheet.flatten([{
      width: _width,
      height: _height
    }, style]);
    const maxHeight = typeof height === 'number' ? height : undefined;
    const maxWidth = typeof width === 'number' ? width : undefined;
    uri = getResizedImage(getCleanUri(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.createElement(ImageBackgroundBase, _extends({}, remainingProps, {
      source: resizedSource,
      style: [styles.image, style],
      testID: testID
    }), /*#__PURE__*/React.createElement(Gradient, {
      testID: `${testID}-gradient`,
      colors: gradient,
      style: _style
    }, children));
  }
  return /*#__PURE__*/React.createElement(ImageBackgroundBase, _extends({}, props, {
    source: resizedSource,
    style: [styles.image, style],
    testID: testID
  }));
};
export default ImageBackground;
//# sourceMappingURL=index.native.js.map