"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.LabeledIconButtonDecorator = exports.LabeledIconButtonBase = exports.LabeledIconButton = 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 _Button = require("@enact/ui/Button");
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _LabeledIcon = require("@enact/ui/LabeledIcon");
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Button2 = require("../Button");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _TooltipDecorator = _interopRequireDefault(require("../TooltipDecorator"));
var _LabeledIconButtonModule = _interopRequireDefault(require("./LabeledIconButton.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["backgroundOpacity", "css", "icon", "iconComponent", "highlighted", "pressed", "selected", "spriteCount"];
/**
 * An Agate-themed Labeled Icon component.
 *
 * @example
 * <LabeledIconButton icon="star">Hello Enact!</LabeledIconButton>
 *
 * @module agate/LabeledIconButton
 * @exports LabeledIconButton
 * @exports LabeledIconButtonBase
 * @exports LabeledIconButtonDecorator
 */
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 Button = (0, _Skinnable["default"])(_Button2.ButtonBase);

/**
 * An icon button component with a label.
 *
 * @class LabeledIconButtonBase
 * @memberof agate/LabeledIconButton
 * @extends ui/LabeledIcon.LabeledIconBase
 * @ui
 * @public
 */
var LabeledIconButtonBase = exports.LabeledIconButtonBase = (0, _kind["default"])({
  name: 'LabeledIconButton',
  propTypes: /** @lends agate/LabeledIconButton.LabeledIconButtonBase.prototype */{
    /**
     * The background opacity of this button.
     *
     * Valid values are:
     * * `'opaque'`,
     * * `'lightOpaque'`, and
     * * `'transparent'`.
     *
     * @type {('opaque'|'lightOpaque'|'transparent')}
     * @default 'opaque'
     * @public
     */
    backgroundOpacity: _propTypes2["default"].oneOf(['opaque', 'lightOpaque', 'transparent']),
    /**
     * 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:
     *
     * * `labeledIconButton` - The root component class
     * * `icon` - The icon component class
     * * `label` - The label component class
     * * `selected` - Applied to a `selected` button
     * * `small` - Applied to a LabeledIconButton specifying a `size` of `'small'`
     *
     * @type {Object}
     * @public
     */
    css: _propTypes2["default"].object,
    /**
     * Provides a way to call special interface attention to this button. It will be "featured"
     * in some way by the theme's visual rules.  This property only has an effect when
     * `backgroundOpacity` is "opaque".
     *
     * @type {Boolean}
     * @public
     */
    highlighted: _propTypes2["default"].bool,
    /**
     * The icon displayed within the button.
     *
     * @type {String}
     * @public
     */
    icon: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].bool]),
    /**
     * The component used to render the `icon`.
     *
     * This will receive the `icon` prop as `children` and should handle it appropriately.It
     * will also receive the `flip` and `size` props as set on the component.
     *
     * @type {Component}
     */
    iconComponent: _propTypes["default"].component,
    /**
     * True if button is an icon only button.
     *
     * @type {Boolean}
     * @private
     */
    iconOnly: _propTypes2["default"].bool,
    /**
     * The position of the label in relation to the icon element.
     *
     * Allowed values include:
     * * 'below' (default),
     * * 'above',
     * * 'left',
     * * 'right',
     * * 'before', and
     * * 'after'.
     *
     * The 'before' and 'after' values automatically swap sides when in an RTL locale context.
     *
     * @type {('above'|'after'|'before'|'below'|'left'|'right')}
     * @default 'below'
     * @public
     */
    labelPosition: _propTypes2["default"].oneOf(['above', 'after', 'before', 'below', 'left', 'right']),
    /**
     * Applies the `pressed` CSS class.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    pressed: _propTypes2["default"].bool,
    /**
     * Selects the component.
     *
     * Setting `selected` may be useful when the component represents a toggleable option. The
     * visual effect may be customized using the
     * {@link agate/LabeledIconButton.LabeledIconButtonBase.css|css} prop.
     */
    selected: _propTypes2["default"].bool,
    /**
     * The size of the button.
     *
     * @type {('smallest'|'small'|'large'|'huge')}
     * @default 'large'
     * @public
     */
    size: _propTypes2["default"].oneOf(['smallest', 'small', 'large', 'huge']),
    /**
     * The amount of sprite "cells" in the src image.
     *
     * @type {Number}
     * @public
     */
    spriteCount: _propTypes2["default"].number
    // TODO: spriteCount prop bleeds!  Is this cruft?
  },
  defaultProps: {
    size: 'large'
  },
  styles: {
    css: _LabeledIconButtonModule["default"],
    className: 'labeledIconButton',
    publicClassNames: true
  },
  computed: {
    className: function className(_ref) {
      var selected = _ref.selected,
        size = _ref.size,
        styler = _ref.styler;
      return styler.append({
        selected: selected
      }, size);
    }
  },
  render: function render(_ref2) {
    var backgroundOpacity = _ref2.backgroundOpacity,
      css = _ref2.css,
      icon = _ref2.icon,
      iconComponent = _ref2.iconComponent,
      highlighted = _ref2.highlighted,
      pressed = _ref2.pressed,
      selected = _ref2.selected,
      spriteCount = _ref2.spriteCount,
      rest = _objectWithoutProperties(_ref2, _excluded);
    delete rest.iconOnly;
    return _LabeledIcon.LabeledIconBase.inline(_objectSpread(_objectSpread({
      role: 'button'
    }, rest), {}, {
      icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
        backgroundOpacity: backgroundOpacity,
        css: css,
        icon: icon,
        iconComponent: iconComponent,
        iconOnly: true,
        highlighted: highlighted,
        pressed: pressed,
        selected: selected,
        spriteCount: spriteCount
      }),
      css: css
    }));
  }
});

/**
 * Adds Agate specific behaviors to {@link agate/LabeledIconButton.LabeledIconButtonBase|LabeledIconButtonBase}.
 *
 * @memberof agate/LabeledIconButton
 * @hoc
 * @mixes ui/Button.ButtonDecorator
 * @mixes ui/LabeledIcon.LabeledIconDecorator
 * @mixes spotlight/Spottable.Spottable
 * @mixes agate/Skinnable.Skinnable
 * @mixes agate/TooltipDecorator.TooltipDecorator
 * @public
 */
var LabeledIconButtonDecorator = exports.LabeledIconButtonDecorator = (0, _compose["default"])(_Pure["default"], _Button.ButtonDecorator, _LabeledIcon.LabeledIconDecorator, _TooltipDecorator["default"], _Spottable["default"], _Skinnable["default"]);

/**
 * An Agate-styled icon button component with a label.
 *
 * Usage:
 * ```
 * <LabeledIconButton icon="star" labelPosition="after">
 *   Favorite
 * </LabeledIconButton>
 * ```
 *
 * @class LabeledIconButton
 * @memberof agate/LabeledIconButton
 * @extends agate/LabeledIconButton.LabeledIconButtonBase
 * @mixes agate/LabeledIconButton.LabeledIconButtonDecorator
 * @ui
 * @public
 */
var LabeledIconButton = exports.LabeledIconButton = LabeledIconButtonDecorator(LabeledIconButtonBase);
var _default = exports["default"] = LabeledIconButton;