"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.GridListImageItemDecorator = exports.GridListImageItemBase = exports.GridListImageItem = exports["default"] = void 0;

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

var _kind = _interopRequireDefault(require("@enact/core/kind"));

var _deprecate = _interopRequireDefault(require("@enact/core/internal/deprecate"));

var _util = require("@enact/core/util");

var _GridListImageItem = require("@enact/ui/GridListImageItem");

var _propTypes = _interopRequireDefault(require("prop-types"));

var _compose = _interopRequireDefault(require("ramda/src/compose"));

var _Image = require("../Image");

var _Icon = _interopRequireDefault(require("../Icon"));

var _Skinnable = _interopRequireDefault(require("../Skinnable"));

var _GridListImageItemModule = _interopRequireDefault(require("./GridListImageItem.module.css"));

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

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

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

var parseRatio = /^(\d+):(\d+)$/;
var calcAspectRatio = (0, _util.memoize)(function (aspectRatio) {
  if (aspectRatio === 'square') return 1;
  if (aspectRatio === 'widescreen') return 16 / 9;
  if (typeof aspectRatio === 'number') return 1 / aspectRatio;
  var ratio = aspectRatio.match(parseRatio);

  if (ratio && ratio.length === 3) {
    return parseInt(ratio[2]) / parseInt(ratio[1]);
  }

  return 1;
});
/**
 * @class GridListImageItemBase
 * @memberof agate/GridListImageItem
 * @extends ui/GridListImageItem.GridListImageItem
 * @ui
 * @private
 */

var GridListImageItemBase = (0, _kind["default"])({
  name: 'GridListImageItem',
  propTypes:
  /** @lends agate/GridListImageItem.GridListImageItemBase.prototype */
  {
    /**
     * Determines the ratio of the image's width to its height.
     *
     * The value can either be specified as a number or as a string using the standard format:
     * 'width:height'. The predefined values of `'square'` and `'widescreen'` may also be used
     * for `'1:1'` or `'16:9'`, respectively.
     *
     * @type {Number|String}
     * @public
     */
    aspectRatio: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string]),

    /**
     * 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:
     *
     * * `image` - The image component class
     * * `caption` - The caption component class
     * * `subCaption` - The subCaption component class
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object
  },
  styles: {
    css: _GridListImageItemModule["default"],
    publicClassNames: ['gridListImageItem', 'image', 'caption', 'subCaption']
  },
  computed: {
    style: function style(_ref) {
      var aspectRatio = _ref.aspectRatio,
          _style = _ref.style;
      if (!aspectRatio) return _style;
      return _objectSpread(_objectSpread({}, _style), {}, {
        '--agate-gridlistimageitem-aspect-ratio': calcAspectRatio(aspectRatio)
      });
    }
  },
  render: (0, _deprecate["default"])(function (_ref2) {
    var css = _ref2.css,
        rest = _objectWithoutProperties(_ref2, ["css"]);

    delete rest.aspectRatio;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridListImageItem.GridListImageItem, _objectSpread(_objectSpread({}, rest), {}, {
      css: css,
      iconComponent: _Icon["default"],
      imageComponent: _Image.ImageBase
    }));
  }, {
    name: 'agate/GridListImageItem',
    replacedBy: 'agate/ImageItem',
    until: '2.0.0'
  })
});
/**
 * @hoc
 * @memberof agate/GridListImageItem
 * @mixes agate/Skinnable.Skinnable
 * @private
 */

exports.GridListImageItemBase = GridListImageItemBase;
var GridListImageItemDecorator = (0, _compose["default"])(_Skinnable["default"]);
/**
 * @class GridListImageItem
 * @memberof agate/GridListImageItem
 * @extends agate/GridListImageItem.GridListImageItemBase
 * @mixes agate/GridListImageItem.GridListImageItemDecorator
 * @ui
 * @private
 */

exports.GridListImageItemDecorator = GridListImageItemDecorator;
var GridListImageItem = GridListImageItemDecorator(GridListImageItemBase);
exports.GridListImageItem = GridListImageItem;
var _default = GridListImageItem;
exports["default"] = _default;