"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.ImageItemDecorator = exports.ImageItemBase = exports.ImageItem = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _ImageItem = require("@enact/ui/ImageItem");
var _Marquee = require("@enact/ui/Marquee");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Image = _interopRequireDefault(require("../Image"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _ImageItemModule = _interopRequireDefault(require("./ImageItem.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["captionPosition", "children", "css", "disabled", "orientation", "skin", "src"];
/**
 * Agate styled ImageItem.
 *
 * @example
 * <ImageItem
 * 	src="https://dummyimage.com/64/e048e0/0011ff"
 * 	style={{height: 64, width: 64}}
 * />
 *
 * @module agate/ImageItem
 * @exports ImageItem
 * @exports ImageItemBase
 * @exports ImageItemDecorator
 */
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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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 MarqueeImageItem = (0, _Marquee.MarqueeDecorator)(_ImageItem.ImageItem);

/**
 * An Agate styled ImageItem.
 *
 * @class ImageItemBase
 * @memberof agate/ImageItem
 * @extends ui/ImageItem.ImageItem
 * @ui
 * @public
 */
var ImageItemBase = exports.ImageItemBase = (0, _kind["default"])({
  name: 'ImageItem',
  propTypes: /** @lends agate/ImageItem.ImageItemBase.prototype */{
    /**
     * Sets the position for caption.
     * This props is only valid when `orientation` is `vertical`.
     *
     * @type {('below'|'overlay')}
     * @default 'below'
     * @public
     */
    captionPosition: _propTypes["default"].oneOf(['below', 'overlay']),
    /**
     * The caption displayed with the image.
     *
     * @type {Node}
     * @public
     */
    children: _propTypes["default"].node,
    /**
     * 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:
     *
     * * `imageItem` - The root component class
     * * `caption` - The caption component class
     * * `horizontal` - Applied when `orientation="horizontal"`
     * * `image` - The image component class
     * * `vertical` - Applied when `orientation="vertical"`
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * Disables the `ImageItem`.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes["default"].bool,
    /**
     * The layout orientation of the component.
     *
     * @type {('horizontal'|'vertical')}
     * @default 'vertical'
     * @public
     */
    orientation: _propTypes["default"].oneOf(['horizontal', 'vertical']),
    /**
     * Used to set the `background-size` of the image.
     *
     * @type {String}
     * @default 'fill'
     * @public
     */
    sizing: _propTypes["default"].oneOf(['fit', 'fill', 'none']),
    /**
     * The current skin.
     *
     * @type {String}
     * @private
     */
    skin: _propTypes["default"].string,
    /**
     * String value or Object of values used to determine which image will appear on a specific
     * screenSize.
     *
     * @type {String|Object}
     * @public
     */
    src: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object])
  },
  defaultProps: {
    captionPosition: 'below',
    orientation: 'vertical',
    sizing: 'fill'
  },
  styles: {
    css: _ImageItemModule["default"],
    className: 'imageItem',
    publicClassNames: ['imageItem', 'caption', 'image']
  },
  computed: {
    className: function className(_ref) {
      var captionPosition = _ref.captionPosition,
        styler = _ref.styler,
        sizing = _ref.sizing;
      return styler.append({
        captionOverlay: captionPosition === 'overlay'
      }, sizing);
    }
  },
  render: function render(_ref2) {
    var captionPosition = _ref2.captionPosition,
      children = _ref2.children,
      css = _ref2.css,
      disabled = _ref2.disabled,
      orientation = _ref2.orientation,
      skin = _ref2.skin,
      src = _ref2.src,
      rest = _objectWithoutProperties(_ref2, _excluded);
    var _ref3 = children && (orientation === 'horizontal' || captionPosition === 'below') ? [MarqueeImageItem, {
        alignment: skin === 'silicon' && orientation === 'horizontal' ? 'left' : 'center'
      }] : [_ImageItem.ImageItem, null],
      _ref4 = _slicedToArray(_ref3, 2),
      Component = _ref4[0],
      marqueeProps = _ref4[1];
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread(_objectSpread({}, rest), marqueeProps), {}, {
      "aria-disabled": disabled,
      css: css,
      disabled: disabled,
      imageComponent: _Image["default"],
      orientation: orientation,
      src: src,
      children: children
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/ImageItem.ImageItemBase|ImageItemBase}
 *
 * @hoc
 * @memberof agate/ImageItem
 * @mixes ui/Marquee.MarqueeController
 * @mixes agate/Skinnable.Skinnable
 * @mixes spotlight/Spottable.Spottable
 * @public
 */
var ImageItemDecorator = exports.ImageItemDecorator = (0, _compose["default"])((0, _Marquee.MarqueeController)({
  marqueeOnFocus: true
}), (0, _Skinnable["default"])({
  prop: 'skin'
}), _Spottable["default"]);

/**
 * An Agate styled ImageItem with built-in support for marqueed text, and Spotlight focus.
 *
 * @class ImageItem
 * @memberof agate/ImageItem
 * @extends agate/ImageItem.ImageItemBase
 * @mixes agate/ImageItem.ImageItemDecorator
 * @ui
 * @public
 */
var ImageItem = exports.ImageItem = ImageItemDecorator(ImageItemBase);
var _default = exports["default"] = ImageItem;