function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _excluded = ["children", "overlay", "onOverlayClick"],
  _excluded2 = ["children"],
  _excluded3 = ["children"],
  _excluded4 = ["children"],
  _excluded5 = ["orientation", "children"],
  _excluded6 = ["orientation", "children"],
  _excluded7 = ["disabled", "checked", "defaultChecked", "orientation", "style", "className"],
  _excluded8 = ["role"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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 { useCheckbox, useCheckboxGroupItem } from '@react-aria/checkbox';
import { useFocusRing } from '@react-aria/focus';
import { mergeProps } from '@react-aria/utils';
import { VisuallyHidden } from '@react-aria/visually-hidden';
import React from 'react';
import { useToggleState } from 'react-stately';
import { CheckboxGroupContext } from '../CheckboxGroup/CheckboxGroup';
import { StyledActions } from '../Content/Content.styles';
import { StyledFooter, StyledHeroMedia, StyledHeroOverlay, StyledHeroText, StyledInteractableTile, StyledLinkTile, StyledSelectableTile, StyledTileContent } from '../Tile/Tile.styles';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { mergeRefs } from '../_utils/mergeRefs';
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));
});
function noop() {}
var CheckboxTile_ = /*#__PURE__*/React.forwardRef(function CheckboxTile(_ref7, ref) {
  var _ref7$disabled = _ref7.disabled,
    disabled = _ref7$disabled === void 0 ? false : _ref7$disabled,
    checked = _ref7.checked,
    defaultChecked = _ref7.defaultChecked,
    orientation = _ref7.orientation,
    style = _ref7.style,
    className = _ref7.className,
    props_ = _objectWithoutProperties(_ref7, _excluded7);
  var props = _objectSpread(_objectSpread({}, props_), {}, {
    isDisabled: disabled,
    isSelected: checked,
    defaultSelected: defaultChecked
  });
  var inputRef = React.useRef(null);
  // Group hooks
  var groupState = React.useContext(CheckboxGroupContext);
  var isGroup = Boolean(groupState);
  var _useCheckboxGroupItem = useCheckboxGroupItem(props, groupState !== null && groupState !== void 0 ? groupState : {
      isSelected: noop
    }, inputRef),
    inputGroupItemProps = _useCheckboxGroupItem.inputProps;
  // Single hooks
  var state = useToggleState(props);
  var _useCheckbox = useCheckbox(props, state, inputRef),
    inputProps = _useCheckbox.inputProps;
  // common hooks
  var _useFocusRing = useFocusRing(),
    focusProps = _useFocusRing.focusProps,
    isFocusVisible = _useFocusRing.isFocusVisible;
  var isDisabled = isGroup ? groupState.isDisabled || disabled : disabled;
  var isSelected = isGroup ? groupState.isSelected(props.value) : state.isSelected;
  return /*#__PURE__*/React.createElement(StyledSelectableTile, {
    $disabled: isDisabled,
    $selected: isSelected,
    $focused: isFocusVisible,
    $orientation: orientation,
    as: "label",
    className: className,
    style: style
  }, /*#__PURE__*/React.createElement(VisuallyHidden, null, /*#__PURE__*/React.createElement("input", _extends({}, mergeProps(isGroup ? inputGroupItemProps : inputProps, focusProps), {
    ref: mergeRefs(inputRef, ref)
  }))), /*#__PURE__*/React.createElement(TileContext.Provider, {
    value: {
      orientation: orientation
    }
  }, props.children));
});
function TileInner(_ref8, ref) {
  var _ref8$role = _ref8.role,
    role = _ref8$role === void 0 ? 'none' : _ref8$role,
    props = _objectWithoutProperties(_ref8, _excluded8);
  switch (role) {
    case 'none':
      return /*#__PURE__*/React.createElement(InteractableTile, _extends({
        ref: ref
      }, props));
    case 'link':
      return /*#__PURE__*/React.createElement(LinkTile, _extends({
        ref: ref
      }, props));
    case 'checkbox':
      return /*#__PURE__*/React.createElement(CheckboxTile_, _extends({
        ref: ref
      }, props));
    default:
      return null;
  }
}
var Tile_ = /*#__PURE__*/React.forwardRef(TileInner);

/**
 * <NextTile role={checkbox}/> can be used as single checkbox as well as in group.
 *
 * Single
 * ```
 * <NextTile role={checkbox} value="ThomasAnderson" onChange=((value) => console.log(value) />
 * <NextTile role={checkbox} value="WhiteRabbit" onChange=((value) => console.log(value) />
 * ```
 *
 * Group
 * ```
 * <CheckboxGroup label="Matrix" onChange=((value) => console.log(value)>
 *    <NextTile role={checkbox} value="ThomasAnderson"/>
 *    <NextTile role={checkbox} value="WhiteRabbit"/>
 * </CheckboxGroup>
 * ```
 *
 * @since 11.6.0
 */
export var NextTile = addSubcomponents({
  Actions: Actions,
  Content: Content,
  Footer: Footer,
  HeroText: HeroText,
  HeroMedia: HeroMedia
}, Tile_);
//# sourceMappingURL=NextTile.js.map