"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RadioItemDecorator = exports.RadioItemBase = exports.RadioItem = 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 _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"));

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

/**
 * 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
 */
var 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
  },
  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,
        rest = _objectWithoutProperties(_ref2, ["children", "css", "icon", "selected"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Item["default"], _objectSpread(_objectSpread({
      "aria-checked": selected,
      role: "checkbox"
    }, rest), {}, {
      css: css,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], {
        slot: "slotBefore",
        className: css.icon,
        size: "small",
        children: icon
      }), children]
    }));
  }
});
/**
 * Applies Agate specific behaviors to [RadioItem]{@link agate/RadioItem.RadioItem} components.
 *
 * @hoc
 * @memberof agate/RadioItem
 * @mixes ui/Toggleable.Toggleable
 * @mixes ui/Touchable.Touchable
 * @mixes spotlight/Spottable.Spottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.RadioItemBase = RadioItemBase;
var RadioItemDecorator = (0, _compose["default"])((0, _Toggleable["default"])({
  toggleProp: 'onTap'
}), _Touchable["default"], _Spottable["default"], _Skinnable["default"]);
/**
 * An Agate-styled RadioItem.
 *
 * @class RadioItem
 * @memberof agate/RadioItem
 * @extends agate/RadioItem.RadioItemBase
 * @mixes agate/RadioItem.RadioItemDecorator
 * @ui
 * @public
 */

exports.RadioItemDecorator = RadioItemDecorator;
var RadioItem = RadioItemDecorator(RadioItemBase);
exports.RadioItem = RadioItem;
var _default = RadioItem;
exports["default"] = _default;