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); }

/*
Copyright (c) 2018-2019 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/index.js';
import { mergeOverrides } from '../helpers/overrides.js';

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'
  }
});

export const AspectRatioBox = ({
  aspectRatio,
  overrides,
  ...restProps
}) => {
  const aspectRatioBoxOverrides = {
    Block: {
      style: aspectRatioBoxStyle
    }
  };
  const blockOverrides = mergeOverrides(aspectRatioBoxOverrides, overrides);
  return React.createElement(Block, _extends({
    overrides: blockOverrides,
    $aspectRatio: aspectRatio,
    "data-baseweb": "aspect-ratio-box"
  }, restProps));
};
AspectRatioBox.defaultProps = {
  aspectRatio: 1,
  overrides: {}
};
export default AspectRatioBox;