"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LabeledIconButtonDecorator = exports.LabeledIconButtonBase = exports.LabeledIconButton = exports["default"] = void 0;

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

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

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 _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 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 = (0, _kind["default"])({
  name: 'LabeledIconButton',
  propTypes:
  /** @lends agate/LabeledIconButton.LabeledIconButtonBase.prototype */
  {
    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,
    // forwarded from Spottable
    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
     * [css]{@link agate/LabeledIconButton.LabeledIconButtonBase.css} prop.
     */
    selected: _propTypes2["default"].bool,

    /**
     * The amount of sprite "cells" in the src image.
     *
     * @type {Number}
     * @public
     */
    spriteCount: _propTypes2["default"].number // TODO: spriteCount prop bleeds!  Is this cruft?

  },
  styles: {
    css: _LabeledIconButtonModule["default"],
    className: 'labeledIconButton',
    publicClassNames: true
  },
  render: function render(_ref) {
    var backgroundOpacity = _ref.backgroundOpacity,
        css = _ref.css,
        icon = _ref.icon,
        iconComponent = _ref.iconComponent,
        highlighted = _ref.highlighted,
        pressed = _ref.pressed,
        selected = _ref.selected,
        spriteCount = _ref.spriteCount,
        rest = _objectWithoutProperties(_ref, ["backgroundOpacity", "css", "icon", "iconComponent", "highlighted", "pressed", "selected", "spriteCount"]);

    delete rest.iconOnly;
    return _LabeledIcon.LabeledIconBase.inline(_objectSpread(_objectSpread({
      role: 'button'
    }, rest), {}, {
      icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
        backgroundOpacity: backgroundOpacity,
        icon: icon,
        iconComponent: iconComponent,
        iconOnly: true,
        highlighted: highlighted,
        pressed: pressed,
        selected: selected,
        spriteCount: spriteCount
      }),
      css: css
    }));
  }
});
/**
 * Adds Agate specific behaviors to [LabeledIconButtonBase]{@link agate/LabeledIconButton.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
 */

exports.LabeledIconButtonBase = LabeledIconButtonBase;
var 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
 */

exports.LabeledIconButtonDecorator = LabeledIconButtonDecorator;
var LabeledIconButton = LabeledIconButtonDecorator(LabeledIconButtonBase);
exports.LabeledIconButton = LabeledIconButton;
var _default = LabeledIconButton;
exports["default"] = _default;