"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.RadioItemDecorator = exports.RadioItemBase = exports.RadioItem = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));
var _Toggleable = _interopRequireDefault(require("@enact/ui/Toggleable"));
var _Touchable = _interopRequireDefault(require("@enact/ui/Touchable"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Icon = _interopRequireDefault(require("../Icon"));
var _Item = _interopRequireDefault(require("../Item"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _RadioItemModule = _interopRequireDefault(require("./RadioItem.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css", "icon", "selected", "skin", "slotBefore"];
/**
 * Provides Agate-themed Item component and interactive radio toggle icon.
 *
 * @example
 * <RadioItem>Item</RadioItem>
 *
 * @module agate/RadioItem
 * @exports RadioItem
 * @exports RadioItemBase
 * @exports RadioItemDecorator
 */
/**
 * Renders an `Item` with a radio-dot component. Useful to show a selected state on an Item.
 *
 * @class RadioItemBase
 * @memberof agate/RadioItem
 * @extends agate/Item.Item
 * @ui
 * @public
 */
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 RadioItemBase = exports.RadioItemBase = (0, _kind["default"])({
  name: 'RadioItemBase',
  propTypes: /** @lends agate/RadioItem.RadioItemBase.prototype */{
    /**
     * 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:
     *
     * * `radioIcon` - Class name for the radio toggle icon
     * * `radioItem` - The root class name
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * The icon to display when selected.
     *
     * @type {String}
     * @see {@link agate/Icon.Icon}
     * @default 'circle'
     */
    icon: _propTypes["default"].string,
    /**
     * Sets the RadioItem to its 'on' state.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    selected: _propTypes["default"].bool,
    /**
     * The current skin for this component.
     *
     * @type {String}
     * @private
     */
    skin: _propTypes["default"].string,
    /**
     * Nodes to be inserted after the radio button and before `children`.
     *
     * @type {Node}
     * @public
     */
    slotBefore: _propTypes["default"].node
  },
  defaultProps: {
    icon: 'circle',
    selected: false
  },
  styles: {
    css: _RadioItemModule["default"],
    className: 'radioItem',
    publicClassNames: true
  },
  computed: {
    className: function className(_ref) {
      var css = _ref.css,
        selected = _ref.selected,
        styler = _ref.styler;
      return styler.append(selected && css.selected);
    }
  },
  render: function render(_ref2) {
    var children = _ref2.children,
      css = _ref2.css,
      icon = _ref2.icon,
      selected = _ref2.selected,
      skin = _ref2.skin,
      slotBefore = _ref2.slotBefore,
      rest = _objectWithoutProperties(_ref2, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Item["default"], _objectSpread(_objectSpread(_objectSpread({
      "aria-checked": selected,
      role: "checkbox"
    }, rest), {}, {
      css: css
    }, skin === 'silicon' ? {
      size: 'small'
    } : {}), {}, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("slotBefore", {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], {
          className: css.icon,
          size: icon === 'circle' ? 'small' : 'smallest',
          children: icon
        }), slotBefore]
      }), children]
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/RadioItem.RadioItem|RadioItem} components.
 *
 * @hoc
 * @memberof agate/RadioItem
 * @mixes ui/Toggleable.Toggleable
 * @mixes ui/Touchable.Touchable
 * @mixes spotlight/Spottable.Spottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var RadioItemDecorator = exports.RadioItemDecorator = (0, _compose["default"])((0, _Toggleable["default"])({
  toggleProp: 'onTap'
}), _Touchable["default"], (0, _Slottable["default"])({
  slots: ['label', 'slotAfter', 'slotBefore']
}), _Spottable["default"], (0, _Skinnable["default"])({
  prop: 'skin'
}));

/**
 * An Agate-styled RadioItem.
 *
 * @class RadioItem
 * @memberof agate/RadioItem
 * @extends agate/RadioItem.RadioItemBase
 * @mixes agate/RadioItem.RadioItemDecorator
 * @ui
 * @public
 */
var RadioItem = exports.RadioItem = (0, _Pure["default"])(RadioItemDecorator(RadioItemBase));
var _default = exports["default"] = RadioItem;