"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.ItemDecorator = exports.ItemBase = exports.Item = void 0;
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _Item = require("@enact/ui/Item");
var _Layout = require("@enact/ui/Layout");
var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Marquee = require("../Marquee");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _ItemModule = _interopRequireDefault(require("./Item.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["centered", "content", "css", "marqueeOn", "label", "labelPosition", "orientation", "styler"],
  _excluded2 = ["centered", "children", "componentRef", "css", "inline", "label", "labelPosition", "marqueeOn", "slotAfter", "slotBefore"];
/**
 * Provides Agate-themed item components and behaviors. Useful for content in lists.
 *
 * @example
 * <Item>Hello Enact!</Item>
 *
 * @module agate/Item
 * @exports Item
 * @exports ItemBase
 * @exports ItemDecorator
 */
/**
 * Renders the Item content.
 *
 * @class ItemContent
 * @memberof agate/Item
 * @ui
 * @private
 */
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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) { _defineProperty(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; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
var ItemContent = (0, _kind["default"])({
  name: 'ItemContent',
  propTypes: /** @lends agate/Item.ItemContent.prototype */{
    /**
     * Centers the content.
     *
     * @type {Boolean}
     * @public
     */
    centered: _propTypes2["default"].bool,
    /**
     * Text displayed when passed as children.
     *
     * @type {*}
     * @public
     */
    content: _propTypes2["default"].any,
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * The following classes are supported:
     *
     * `label` - The label class name
     *
     * @type {Object}
     * @public
     */
    css: _propTypes2["default"].object,
    /**
     * Text displayed when passed in `label` prop.
     *
     * @type {*}
     * @public
     */
    label: _propTypes2["default"].any,
    /**
     * The position of the label relative to the primary content, `content`.
     *
     * @type {('above'|'after'|'before'|'below')}
     * @default 'below'
     * @public
     */
    labelPosition: _propTypes2["default"].oneOf(['above', 'after', 'before', 'below']),
    /**
     * Determines what triggers the marquee to start its animation.
     *
     * @type {('focus'|'hover'|'render')}
     * @public
     */
    marqueeOn: _propTypes2["default"].oneOf(['focus', 'hover', 'render'])
  },
  defaultProps: {
    labelPosition: 'below'
  },
  styles: {
    className: 'itemContent',
    css: _ItemModule["default"],
    publicClassNames: ['itemContent', 'label']
  },
  computed: {
    className: function className(_ref) {
      var labelPosition = _ref.labelPosition,
        styler = _ref.styler;
      return styler.append({
        labelAbove: labelPosition === 'above',
        labelAfter: labelPosition === 'after',
        labelBefore: labelPosition === 'before',
        labelBelow: labelPosition === 'below'
      });
    },
    orientation: function orientation(_ref2) {
      var labelPosition = _ref2.labelPosition;
      return labelPosition === 'above' || labelPosition === 'below' ? 'vertical' : 'horizontal';
    }
  },
  // eslint-disable-next-line enact/prop-types
  render: function render(_ref3) {
    var centered = _ref3.centered,
      content = _ref3.content,
      css = _ref3.css,
      marqueeOn = _ref3.marqueeOn,
      label = _ref3.label,
      labelPosition = _ref3.labelPosition,
      orientation = _ref3.orientation,
      styler = _ref3.styler,
      rest = _objectWithoutProperties(_ref3, _excluded);
    if (!label) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, _objectSpread(_objectSpread({}, rest), {}, {
        component: _Marquee.Marquee,
        className: styler.append(css.content),
        marqueeOn: marqueeOn,
        children: content
      }));
    } else {
      var verticalAlign = labelPosition === 'before' || labelPosition === 'after' ? 'center' : 'unset';
      var contentAlign = centered ? 'center center' : "".concat(verticalAlign, " unset");
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, _objectSpread(_objectSpread({}, rest), {}, {
        children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Layout, {
          align: contentAlign,
          orientation: orientation,
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
            component: _Marquee.Marquee,
            className: css.content,
            marqueeOn: marqueeOn,
            shrink: orientation === 'vertical' || centered,
            children: content
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
            component: _Marquee.Marquee,
            className: css.label,
            marqueeOn: marqueeOn,
            shrink: true,
            children: label
          })]
        })
      }));
    }
  }
});

/**
 * Renders an Agate-styled Item without any behavior.
 *
 * @class ItemBase
 * @memberof agate/Item
 * @extends ui/Item.ItemBase
 * @ui
 * @public
 */
var ItemBase = exports.ItemBase = (0, _kind["default"])({
  name: 'Item',
  propTypes: /** @lends agate/Item.ItemBase.prototype */{
    /**
     * Centers the slots and content.
     *
     * @type {Boolean}
     * @public
     */
    centered: _propTypes2["default"].bool,
    /**
     * Called with a reference to the root component.
     *
     * @type {Function|Object}
     * @public
     */
    componentRef: _propTypes["default"].ref,
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * The following classes are supported:
     *
     * `item` - The root class name
     * `slotBefore` - The slot (container) preceding the text of this component
     * `slotAfter` - The slot (container) following the text of this component
     * `selected` - Applied to a `selected` button
     *
     * @type {Object}
     * @public
     */
    css: _propTypes2["default"].object,
    /**
     * Applies a disabled style and the control becomes non-interactive.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes2["default"].bool,
    /**
     * Applies inline styling to the item.
     *
     * @type {Boolean}
     * @public
     */
    inline: _propTypes2["default"].bool,
    /**
     * The label to be displayed along with the text.
     *
     * @type {Node}
     * @public
     */
    label: _propTypes2["default"].node,
    /**
     * The position of the label relative to the primary content, `children`.
     *
     * @type {('above'|'after'|'before'|'below')}
     * @default 'below'
     * @public
     */
    labelPosition: _propTypes2["default"].oneOf(['above', 'after', 'before', 'below']),
    /**
     * Determines what triggers the marquee to start its animation.
     *
     * @type {('focus'|'hover'|'render')}
     * @public
     */
    marqueeOn: _propTypes2["default"].oneOf(['focus', 'hover', 'render']),
    /**
     * Applies a selected style to the component.
     *
     * @type {Boolean}
     * @private
     */
    selected: _propTypes2["default"].bool,
    /**
     * The size of the item.
     *
     * @type {('small'|'large')}
     * @default 'large'
     * @public
     */
    size: _propTypes2["default"].oneOf(['small', 'large']),
    /**
     * Nodes to be inserted after `children`.
     *
     * For LTR locales, the nodes are inserted to the right of the primary content. For RTL
     * locales, the nodes are inserted to the left. If nothing is specified, nothing, not even
     * an empty container, is rendered in this place.
     *
     * @type {Node}
     * @public
     */
    slotAfter: _propTypes2["default"].node,
    /**
     * Nodes to be inserted before `children` and `label`.
     *
     * For LTR locales, the nodes are inserted to the left of the primary content. For RTL
     * locales, the nodes are inserted to the right. If nothing is specified, nothing, not even
     * an empty container, is rendered in this place.
     *
     * @type {Node}
     * @public
     */
    slotBefore: _propTypes2["default"].node
  },
  defaultProps: {
    labelPosition: 'below',
    size: 'large'
  },
  styles: {
    css: _ItemModule["default"],
    publicClassNames: ['item', 'itemContent', 'label', 'selected', 'slotAfter', 'slotBefore']
  },
  computed: {
    className: function className(_ref4) {
      var centered = _ref4.centered,
        label = _ref4.label,
        selected = _ref4.selected,
        size = _ref4.size,
        slotAfter = _ref4.slotAfter,
        slotBefore = _ref4.slotBefore,
        styler = _ref4.styler;
      return styler.append({
        hasLabel: label != null,
        selected: selected,
        centered: centered,
        slotAfter: slotAfter,
        slotBefore: slotBefore
      }, size);
    },
    label: function label(_ref5) {
      var _label = _ref5.label;
      return typeof _label === 'number' ? _label.toString() : _label;
    }
  },
  render: function render(_ref6) {
    var centered = _ref6.centered,
      children = _ref6.children,
      componentRef = _ref6.componentRef,
      css = _ref6.css,
      inline = _ref6.inline,
      label = _ref6.label,
      labelPosition = _ref6.labelPosition,
      marqueeOn = _ref6.marqueeOn,
      slotAfter = _ref6.slotAfter,
      slotBefore = _ref6.slotBefore,
      rest = _objectWithoutProperties(_ref6, _excluded2);
    delete rest.size;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Item.ItemBase, _objectSpread(_objectSpread({
      component: _Layout.Row,
      align: centered ? 'center center' : 'center',
      ref: componentRef
    }, rest), {}, {
      inline: inline,
      css: css,
      children: [slotBefore ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
        className: css.slotBefore,
        shrink: true,
        children: slotBefore
      }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(ItemContent, {
        centered: centered,
        content: children,
        css: css,
        label: label,
        labelPosition: labelPosition,
        marqueeOn: marqueeOn,
        shrink: inline
      }), slotAfter ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Cell, {
        className: css.slotAfter,
        shrink: true,
        children: slotAfter
      }) : null]
    }));
  }
});

/**
 * Agate specific behaviors to apply to {@link agate/Item.ItemBase|Item}.
 *
 * @class ItemDecorator
 * @hoc
 * @memberof agate/Item
 * @mixes ui/Item.ItemDecorator
 * @mixes agate/Marquee.MarqueeController
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @mixes spotlight/Spottable.Spottable
 * @public
 */
var ItemDecorator = exports.ItemDecorator = (0, _compose["default"])(_Item.ItemDecorator, (0, _Slottable["default"])({
  slots: ['label', 'slotAfter', 'slotBefore']
}), _Spottable["default"], (0, _Marquee.MarqueeController)({
  marqueeOnFocus: true,
  invalidateProps: ['inline']
}), _Skinnable["default"]);

/**
 * An item component with Agate behaviors applied.
 *
 * Usage:
 * ```
 * <Item>Item Content</Item>
 * ```
 *
 * @class Item
 * @memberof agate/Item
 * @extends agate/Item.ItemBase
 * @mixes agate/Item.ItemDecorator
 * @ui
 * @public
 */
var Item = exports.Item = (0, _Pure["default"])(ItemDecorator(ItemBase));
var _default = exports["default"] = Item;