"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ImageItemDecorator = exports.ImageItemBase = exports.ImageItem = exports["default"] = void 0;

var _jsxRuntime = require("react/jsx-runtime");

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"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

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; }

var MarqueeImageItem = (0, _Marquee.MarqueeDecorator)(_ImageItem.ImageItem);
/**
 * An Agate styled ImageItem.
 *
 * @class ImageItemBase
 * @memberof agate/ImageItem
 * @extends ui/ImageItem.ImageItem
 * @ui
 * @public
 */

var ImageItemBase = (0, _kind["default"])({
  name: 'ImageItem',
  propTypes:
  /** @lends agate/ImageItem.ImageItemBase.prototype */
  {
    /**
     * Sets the position for caption.
     * Available positions: 'below' (default) and 'overlay'.
     *
     * @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']),

    /**
     * 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: {
    orientation: 'vertical',
    captionPosition: 'below'
  },
  styles: {
    css: _ImageItemModule["default"],
    className: 'imageItem'
  },
  computed: {
    className: function className(_ref) {
      var captionPosition = _ref.captionPosition,
          styler = _ref.styler;
      return styler.append({
        captionOverlay: captionPosition === 'overlay'
      });
    }
  },
  render: function render(_ref2) {
    var captionPosition = _ref2.captionPosition,
        children = _ref2.children,
        css = _ref2.css,
        disabled = _ref2.disabled,
        src = _ref2.src,
        rest = _objectWithoutProperties(_ref2, ["captionPosition", "children", "css", "disabled", "src"]);

    var _ref3 = children && captionPosition === 'below' ? [MarqueeImageItem, {
      alignment: '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"],
      src: src,
      children: children
    }));
  }
});
/**
 * Applies Agate specific behaviors to [ImageItemBase]{@link agate/ImageItem.ImageItemBase}
 *
 * @hoc
 * @memberof agate/ImageItem
 * @mixes ui/Marquee.MarqueeController
 * @mixes agate/Skinnable.Skinnable
 * @mixes spotlight/Spottable.Spottable
 * @public
 */

exports.ImageItemBase = ImageItemBase;
var ImageItemDecorator = (0, _compose["default"])((0, _Marquee.MarqueeController)({
  marqueeOnFocus: true
}), _Skinnable["default"], _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
 */

exports.ImageItemDecorator = ImageItemDecorator;
var ImageItem = ImageItemDecorator(ImageItemBase);
exports.ImageItem = ImageItem;
var _default = ImageItem;
exports["default"] = _default;