function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }

/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { Block } from '../block';
import { mergeOverrides } from '../helpers/overrides';

const aspectRatioBoxStyle = ({
  $aspectRatio
}) => ({
  position: 'relative',
  '::before': {
    content: '""',
    width: '1px',
    marginLeft: '-1px',
    float: 'left',
    height: 0,
    paddingTop: `${100 / $aspectRatio}%`,
    pointerEvents: 'none'
  },
  '::after': {
    content: '""',
    display: 'table',
    clear: 'both'
  }
});

const AspectRatioBox = ({
  forwardedRef,
  aspectRatio = 1,
  overrides = {},
  ...restProps
}) => {
  const aspectRatioBoxOverrides = {
    Block: {
      style: aspectRatioBoxStyle
    }
  };
  const blockOverrides = mergeOverrides(aspectRatioBoxOverrides, overrides);
  return /*#__PURE__*/React.createElement(Block // coerced to any because of how react components are typed.
  // cannot guarantee an html element
  , _extends({
    ref: forwardedRef,
    overrides: blockOverrides,
    $aspectRatio: aspectRatio,
    "data-baseweb": "aspect-ratio-box"
  }, restProps));
};

const AspectRatioBoxComponent = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(AspectRatioBox, _extends({}, props, {
  forwardedRef: ref
})));
AspectRatioBoxComponent.displayName = 'AspectRatioBox';
export default AspectRatioBoxComponent;