"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CheckboxItemDecorator = exports.CheckboxItemBase = exports.CheckboxItem = exports["default"] = void 0;

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

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

var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));

var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));

var _Toggleable = _interopRequireDefault(require("@enact/ui/Toggleable"));

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

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

var _Checkbox = require("../Checkbox");

var _Item = require("../Item");

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

var _CheckboxItemModule = _interopRequireDefault(require("./CheckboxItem.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 Item = (0, _Item.ItemDecorator)(_Item.ItemBase);
var Checkbox = (0, _Skinnable["default"])(_Checkbox.CheckboxBase);
Checkbox.displayName = 'Checkbox';
/**
 * An item with a checkbox component, ready to use in Agate applications.
 *
 * `CheckboxItem` may be used to allow the user to select a single option or used as part of a
 * [Group]{@link ui/Group} when multiple [selections]{@link ui/Group.Group.select} are possible.
 *
 * Usage:
 * ```
 * <CheckboxItem
 *   defaultSelected={selected}
 *   onToggle={handleToggle}
 * >
 *   Item with a Checkbox
 * </CheckboxItem>
 * ```
 *
 * @class CheckboxItemBase
 * @memberof agate/CheckboxItem
 * @extends agate/Item.Item
 * @omit iconComponent
 * @ui
 * @public
 */

var CheckboxItemBase = (0, _kind["default"])({
  name: 'CheckboxItem',
  propTypes:
  /** @lends agate/CheckboxItem.CheckboxItemBase.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:
     *
     * * `checkboxItem` - The root class name
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,

    /**
     * The icon content.
     *
     * May be specified as either:
     *
     * * A string that represents an icon from the [iconList]{@link ui/Icon.Icon.iconList},
     * * An HTML entity string, Unicode reference or hex value (in the form '0x...'),
     * * A URL specifying path to an icon image, or
     * * An object representing a resolution independent resource (See {@link ui/resolution})
     *
     * @type {String|Object}
     * @public
     */
    icon: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),

    /**
     * Enables the "indeterminate" state.
     *
     * An indeterminate, mixed, or half-selected state is typically used in a hierarchy or group
     * to represent that some, not all, children are selected.
     *
     * NOTE: This does not prevent updating the `selected` state. Applications must control this
     * property directly.
     *
     * @type {Boolean}
     * @public
     */
    indeterminate: _propTypes["default"].bool,

    /**
     * The icon to be used in the `indeterminate` state.
     *
     * May be specified as either:
     *
     * * A string that represents an icon from the [iconList]{@link agate/Icon.Icon.iconList},
     * * An HTML entity string, Unicode reference or hex value (in the form '0x...'),
     * * A URL specifying path to an icon image, or
     * * An object representing a resolution independent resource (See {@link ui/resolution})
     *
     * @type {String}
     * @public
     */
    indeterminateIcon: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),

    /**
     * If true the checkbox will be selected.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    selected: _propTypes["default"].bool,

    /**
     * Nodes to be inserted after the checkbox and before `children`.
     *
     * @type {Node}
     * @public
     */
    slotBefore: _propTypes["default"].node
  },
  styles: {
    css: _CheckboxItemModule["default"],
    className: 'checkboxItem',
    publicClassNames: ['checkboxItem']
  },
  computed: {
    className: function className(_ref) {
      var selected = _ref.selected,
          styler = _ref.styler;
      return styler.append({
        selected: selected
      });
    }
  },
  render: function render(_ref2) {
    var children = _ref2.children,
        css = _ref2.css,
        icon = _ref2.icon,
        indeterminate = _ref2.indeterminate,
        indeterminateIcon = _ref2.indeterminateIcon,
        selected = _ref2.selected,
        slotBefore = _ref2.slotBefore,
        rest = _objectWithoutProperties(_ref2, ["children", "css", "icon", "indeterminate", "indeterminateIcon", "selected", "slotBefore"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Item, _objectSpread(_objectSpread({
      role: "checkbox"
    }, rest), {}, {
      "aria-checked": selected,
      css: css,
      selected: selected,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("slotBefore", {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Checkbox, {
          indeterminate: indeterminate,
          indeterminateIcon: indeterminateIcon,
          selected: selected,
          children: icon
        }), slotBefore]
      }), children]
    }));
  }
});
/**
 * Applies Agate specific behaviors to [CheckboxItem]{@link agate/CheckboxItem.CheckboxItem} components.
 *
 * @hoc
 * @memberof agate/CheckboxItem
 * @mixes ui/Toggleable.Toggleable
 * @mixes ui/Slottable.Slottable
 * @public
 */

exports.CheckboxItemBase = CheckboxItemBase;
var CheckboxItemDecorator = (0, _compose["default"])((0, _Toggleable["default"])({
  toggleProp: 'onClick'
}), (0, _Slottable["default"])({
  slots: ['label', 'slotAfter', 'slotBefore']
}));
/**
 * An Agate-styled item with a checkbox component.
 *
 * `CheckboxItem` will manage its `selected` state via [Toggleable]{@link ui/Toggleable} unless set
 * directly.
 *
 * @class CheckboxItem
 * @memberof agate/CheckboxItem
 * @extends agate/CheckboxItem.CheckboxItemBase
 * @mixes agate/CheckboxItem.CheckboxItemDecorator
 * @ui
 * @public
 */

exports.CheckboxItemDecorator = CheckboxItemDecorator;
var CheckboxItem = (0, _Pure["default"])(CheckboxItemDecorator(CheckboxItemBase));
exports.CheckboxItem = CheckboxItem;
var _default = CheckboxItem;
exports["default"] = _default;