var _excluded = ["children", "overlay", "onOverlayClick"],
  _excluded2 = ["children"],
  _excluded3 = ["children"],
  _excluded4 = ["children"],
  _excluded5 = ["orientation", "children"],
  _excluded6 = ["orientation", "children"],
  _excluded7 = ["orientation", "selected", "onClick", "onKeyDown", "disabled", "children"],
  _excluded8 = ["variant", "orientation"];
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); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { StyledActions } from '../Content/Content.styles';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { mergeRefs } from '../_utils/mergeRefs';
import { StyledFooter, StyledHeroMedia, StyledHeroOverlay, StyledHeroText, StyledInteractableTile, StyledLinkTile, StyledSelectableTile, StyledTileContent } from './Tile.styles';
var heroTextGridTemplateColumns = 'auto 1fr';
var TileContext = /*#__PURE__*/React.createContext({
  orientation: 'portrait'
});
var HeroMedia = /*#__PURE__*/React.forwardRef(function HeroMedia(_ref, ref) {
  var children = _ref.children,
    _ref$overlay = _ref.overlay,
    overlay = _ref$overlay === void 0 ? false : _ref$overlay,
    onOverlayClick = _ref.onOverlayClick,
    props = _objectWithoutProperties(_ref, _excluded);
  var _React$useContext = React.useContext(TileContext),
    orientation = _React$useContext.orientation;
  var heroRef = React.useRef(null);
  React.useLayoutEffect(function () {
    if (orientation === 'landscape') {
      var _heroRef$current, _heroRef$current$pare;
      (_heroRef$current = heroRef.current) === null || _heroRef$current === void 0 ? void 0 : (_heroRef$current$pare = _heroRef$current.parentElement) === null || _heroRef$current$pare === void 0 ? void 0 : _heroRef$current$pare.style.removeProperty('--core-tile-grid-template-columns');
    }
  }, [orientation]);
  return /*#__PURE__*/React.createElement(StyledHeroMedia, _extends({
    ref: mergeRefs(heroRef, ref),
    $orientation: orientation
  }, props), overlay && /*#__PURE__*/React.createElement(StyledHeroOverlay, {
    onClick: onOverlayClick
  }), children);
});
var HeroText = /*#__PURE__*/React.forwardRef(function HeroText(_ref2, ref) {
  var children = _ref2.children,
    props = _objectWithoutProperties(_ref2, _excluded2);
  var _React$useContext2 = React.useContext(TileContext),
    orientation = _React$useContext2.orientation;
  var heroRef = React.useRef(null);
  React.useLayoutEffect(function () {
    if (orientation === 'landscape') {
      var _heroRef$current2, _heroRef$current2$par;
      (_heroRef$current2 = heroRef.current) === null || _heroRef$current2 === void 0 ? void 0 : (_heroRef$current2$par = _heroRef$current2.parentElement) === null || _heroRef$current2$par === void 0 ? void 0 : _heroRef$current2$par.style.setProperty('--core-tile-grid-template-columns', heroTextGridTemplateColumns);
    }
  }, [orientation]);
  return /*#__PURE__*/React.createElement(StyledHeroText, _extends({
    ref: mergeRefs(heroRef, ref),
    $orientation: orientation
  }, props), children);
});
var Content = /*#__PURE__*/React.forwardRef(function Content(props, ref) {
  return /*#__PURE__*/React.createElement(StyledTileContent, _extends({
    ref: ref
  }, props));
});
var Footer = /*#__PURE__*/React.forwardRef(function Footer(_ref3, ref) {
  var children = _ref3.children,
    props = _objectWithoutProperties(_ref3, _excluded3);
  return /*#__PURE__*/React.createElement(StyledFooter, _extends({
    ref: ref
  }, props), children);
});
var Actions = /*#__PURE__*/React.forwardRef(function Actions(_ref4, ref) {
  var children = _ref4.children,
    props = _objectWithoutProperties(_ref4, _excluded4);
  return /*#__PURE__*/React.createElement(StyledActions, _extends({
    ref: ref
  }, props), children);
});
export var InteractableTile = /*#__PURE__*/React.forwardRef(function InteractableTile(_ref5, ref) {
  var orientation = _ref5.orientation,
    children = _ref5.children,
    props = _objectWithoutProperties(_ref5, _excluded5);
  return /*#__PURE__*/React.createElement(StyledInteractableTile, _extends({
    ref: ref,
    $orientation: orientation
  }, props), /*#__PURE__*/React.createElement(TileContext.Provider, {
    value: {
      orientation: orientation
    }
  }, children));
});
export var LinkTile = /*#__PURE__*/React.forwardRef(function LinkTile(_ref6, ref) {
  var orientation = _ref6.orientation,
    children = _ref6.children,
    props = _objectWithoutProperties(_ref6, _excluded6);
  return /*#__PURE__*/React.createElement(StyledLinkTile, _extends({
    ref: ref,
    $orientation: orientation
  }, props), /*#__PURE__*/React.createElement(TileContext.Provider, {
    value: {
      orientation: orientation
    }
  }, children));
});
export var SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile(_ref7, ref) {
  var orientation = _ref7.orientation,
    _ref7$selected = _ref7.selected,
    selected = _ref7$selected === void 0 ? false : _ref7$selected,
    _onClick = _ref7.onClick,
    _onKeyDown = _ref7.onKeyDown,
    _ref7$disabled = _ref7.disabled,
    disabled = _ref7$disabled === void 0 ? false : _ref7$disabled,
    children = _ref7.children,
    props = _objectWithoutProperties(_ref7, _excluded7);
  return /*#__PURE__*/React.createElement(StyledSelectableTile, _extends({
    ref: ref,
    $disabled: disabled,
    $orientation: orientation,
    $selected: selected,
    tabIndex: !disabled ? 0 : undefined,
    onClick: function onClick(e) {
      if (!disabled) {
        _onClick === null || _onClick === void 0 ? void 0 : _onClick();
      }
    },
    onKeyDown: function onKeyDown(e) {
      var code = e.code;
      if (code === 'Enter' || code === 'Space') {
        _onClick === null || _onClick === void 0 ? void 0 : _onClick();
      }
      _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(e);
    }
  }, props), /*#__PURE__*/React.createElement(TileContext.Provider, {
    value: {
      orientation: orientation
    }
  }, children));
});
var Tile_ = /*#__PURE__*/React.forwardRef(function Tile(_ref8, ref) {
  var _ref8$variant = _ref8.variant,
    variant = _ref8$variant === void 0 ? 'interactive' : _ref8$variant,
    _ref8$orientation = _ref8.orientation,
    orientation = _ref8$orientation === void 0 ? 'portrait' : _ref8$orientation,
    props = _objectWithoutProperties(_ref8, _excluded8);
  switch (variant) {
    case 'interactive':
      return /*#__PURE__*/React.createElement(InteractableTile, _extends({
        ref: ref,
        orientation: orientation
      }, props));
    case 'selectable':
      return /*#__PURE__*/React.createElement(SelectableTile, _extends({
        ref: ref,
        orientation: orientation
      }, props));
    case 'link':
      return /*#__PURE__*/React.createElement(LinkTile, _extends({
        ref: ref,
        orientation: orientation
      }, props));
  }
});
export var Tile = addSubcomponents({
  Actions: Actions,
  Content: Content,
  Footer: Footer,
  HeroText: HeroText,
  HeroMedia: HeroMedia
}, Tile_);
//# sourceMappingURL=Tile.js.map