"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.AspectRatio = void 0;

var _style = _interopRequireDefault(require("styled-jsx/style"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _jsxRuntime = require("react/jsx-runtime");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// Generated with util/create-component.js
const AspectRatio = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
  const {
    aspectRatio = "100%",
    internalProps = {},
    children,
    className,
    ...otherProps
  } = props;
  const handleAspectRatio = (0, _react.useMemo)(() => {
    if (aspectRatio.includes("%")) {
      return aspectRatio;
    } else {
      const ratio = aspectRatio.split(":");
      return `${100 / parseFloat((parseFloat(ratio[0]) / parseFloat(ratio[1])).toFixed(2))}%`;
    }
  }, [aspectRatio]);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    ref: ref,
    ...otherProps,
    className: _style.default.dynamic([["4240365932", [handleAspectRatio]]]) + " " + (otherProps && otherProps.className != null && otherProps.className || (0, _classnames.default)("Wps-AspectRatio", className) || ""),
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", { ...internalProps,
      className: _style.default.dynamic([["4240365932", [handleAspectRatio]]]) + " " + (internalProps && internalProps.className != null && internalProps.className || (0, _classnames.default)("Wps-AspectRatioInternal", className) || ""),
      children: children
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_style.default, {
      id: "4240365932",
      dynamic: [handleAspectRatio],
      children: `.Wps-AspectRatio.__jsx-style-dynamic-selector{width:100%;background:transparent;position:relative;padding-bottom:${handleAspectRatio};}.Wps-AspectRatio.__jsx-style-dynamic-selector .Wps-AspectRatioInternal.__jsx-style-dynamic-selector{position:absolute;top:0;left:0;right:0;bottom:0;background:transparent;overflow:hidden;width:100%;height:100%;}`
    })]
  });
});
exports.AspectRatio = AspectRatio;