/* index.tsx generated by @compiled/babel-plugin v0.40.0 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("./index.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _constants = require("../../../../../../constants");
var _elements = require("../../../elements");
var _block = _interopRequireDefault(require("../../block"));
var _excluded = ["ignoreContainerPadding", "onError", "placement", "testId", "overrideUrl", "style", "className"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var previewBlockStyleCommon = null;
var ignoreContainerPaddingStyle = null;

/**
 * Represents a resolved PreviewBlock, which typically contains media or other large format content.
 * @public
 * @param {PreviewBlock} PreviewBlock
 * @see Block
 */
var PreviewBlockResolvedView = function PreviewBlockResolvedView(_ref) {
  var _ref$ignoreContainerP = _ref.ignoreContainerPadding,
    ignoreContainerPadding = _ref$ignoreContainerP === void 0 ? false : _ref$ignoreContainerP,
    onError = _ref.onError,
    placement = _ref.placement,
    testId = _ref.testId,
    overrideUrl = _ref.overrideUrl,
    style = _ref.style,
    className = _ref.className,
    blockProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var _useState = (0, _react.useState)(style !== null && style !== void 0 ? style : {}),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    dynamicStyles = _useState2[0],
    setDynamicStyles = _useState2[1];
  var updateStyles = (0, _react.useCallback)(function () {
    if (placement === _constants.MediaPlacement.Left || placement === _constants.MediaPlacement.Right) {
      var containerPadding = ignoreContainerPadding ? '0px' : 'var(--container-padding)';
      var newStyle = _objectSpread(_objectSpread(_objectSpread({}, style), {}, {
        position: 'absolute',
        top: containerPadding,
        bottom: containerPadding,
        width: "calc(var(--preview-block-width) - ".concat(containerPadding, ")")
      }, placement === _constants.MediaPlacement.Left ? {
        left: containerPadding
      } : {}), placement === _constants.MediaPlacement.Right ? {
        right: containerPadding
      } : {});
      setDynamicStyles(newStyle);
    } else {
      if (ignoreContainerPadding) {
        setDynamicStyles(_objectSpread({}, style));
      }
    }
  }, [ignoreContainerPadding, placement, style]);

  // Should be useLayoutEffect to avoid flicker.
  // Styles should be set before paint.
  (0, _react.useLayoutEffect)(function () {
    updateStyles();
  }, [ignoreContainerPadding, placement, updateStyles, className]);
  var handleOnLoad = (0, _react.useCallback)(function () {
    updateStyles();
  }, [updateStyles]);
  var handleOnError = (0, _react.useCallback)(function () {
    if (onError) {
      onError();
    }
  }, [onError]);
  return /*#__PURE__*/React.createElement(_block.default, (0, _extends2.default)({}, blockProps, {
    testId: "".concat(testId, "-resolved-view"),
    // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
    style: dynamicStyles
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: (0, _runtime.ax)([placement && "_1t26n7od _ze72n7od _10aa1osq _rjuj1osq _mr051dfr", !placement && ignoreContainerPadding && "_18u01ivi _2hwxc10g _e0oi1ya9 _dmhj1ya9", className])
  }), /*#__PURE__*/React.createElement(_elements.Preview, {
    onError: handleOnError,
    onLoad: handleOnLoad,
    overrideUrl: overrideUrl
  }));
};
var _default = exports.default = PreviewBlockResolvedView;