"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.SwitchItemDecorator = exports.SwitchItemBase = exports.SwitchItem = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _handle = _interopRequireWildcard(require("@enact/core/handle"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Toggleable = _interopRequireDefault(require("@enact/ui/Toggleable"));
var _Icon = _interopRequireDefault(require("../Icon"));
var _Item = _interopRequireDefault(require("../Item"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _Switch = require("../Switch");
var _SwitchItemModule = _interopRequireDefault(require("./SwitchItem.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css", "icon", "selected", "switchOffLabel", "switchOnLabel"];
/**
 * Provides Agate-themed Item component and interactive toggle switch icon.
 *
 * @example
 * <SwitchItem>Item</SwitchItem>
 *
 * @module agate/SwitchItem
 * @exports SwitchItem
 * @exports SwitchItemBase
 * @exports SwitchItemDecorator
 */
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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 Switch = (0, _Skinnable["default"])({
  prop: 'skin'
}, _Switch.SwitchBase);

/**
 * Renders an `Item` with a switch component.
 *
 * @class SwitchItemBase
 * @memberof agate/SwitchItem
 * @extends agate/Item.Item
 * @ui
 * @public
 */
var SwitchItemBase = exports.SwitchItemBase = (0, _kind["default"])({
  name: 'SwitchItemBase',
  propTypes: /** @lends agate/SwitchItem.SwitchItemBase.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:
     *
     * * `label` - Class name for the toggle icon label
     * * `switchIcon` - Class name for the toggle icon
     * * `switchItem` - The root class name
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * Disables component and makes it non-interactive.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    disabled: _propTypes["default"].bool,
    /**
     * The icon to display before the text.
     *
     * @type {String|Object}
     * @see {@link agate/Icon.Icon}
     * @public
     */
    icon: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
    /**
     * Sets the switch to the 'on' state.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    selected: _propTypes["default"].bool,
    /**
     * Customize the text displayed when the switch is "off".
     *
     * @type {String}
     * @default 'off'
     * @public
     */
    switchOffLabel: _propTypes["default"].string,
    /**
     * Customize the text displayed when the switch is "on".
     *
     * @type {String}
     * @default 'on'
     * @public
     */
    switchOnLabel: _propTypes["default"].string
  },
  defaultProps: {
    disabled: false,
    selected: false,
    switchOffLabel: 'off',
    switchOnLabel: 'on'
  },
  styles: {
    css: _SwitchItemModule["default"],
    className: 'switchItem',
    publicClassNames: true
  },
  handlers: {
    onClick: (0, _handle["default"])((0, _handle.forProp)('disabled', false), (0, _handle.forward)('onClick'))
  },
  computed: {
    className: function className(_ref) {
      var selected = _ref.selected,
        styler = _ref.styler;
      return styler.append({
        selected: selected
      });
    },
    icon: function icon(_ref2) {
      var css = _ref2.css,
        _icon = _ref2.icon;
      return _icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], {
        size: "small",
        slot: "slotBefore",
        className: css.icon,
        children: _icon
      }) : null;
    }
  },
  render: function render(_ref3) {
    var children = _ref3.children,
      css = _ref3.css,
      icon = _ref3.icon,
      selected = _ref3.selected,
      switchOffLabel = _ref3.switchOffLabel,
      switchOnLabel = _ref3.switchOnLabel,
      rest = _objectWithoutProperties(_ref3, _excluded);
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Item["default"], _objectSpread(_objectSpread({
      "aria-pressed": selected,
      role: "button"
    }, rest), {}, {
      css: css,
      label: selected ? switchOnLabel : switchOffLabel,
      labelPosition: "after",
      children: [icon, children, /*#__PURE__*/(0, _jsxRuntime.jsx)(Switch, {
        className: css.switchIcon,
        selected: selected,
        slot: "slotAfter"
      })]
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/SwitchItem.SwitchItemBase|SwitchItemBase} components.
 *
 * @hoc
 * @memberof agate/SwitchItem
 * @mixes ui/Toggleable.Toggleable
 * @mixes spotlight/Spottable.Spottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var SwitchItemDecorator = exports.SwitchItemDecorator = (0, _compose["default"])((0, _Toggleable["default"])({
  toggleProp: 'onClick'
}),
// Touchable,
_Spottable["default"], _Skinnable["default"]);

/**
 * An Agate-styled item with a switch component.
 *
 * `SwitchItem` will manage its `selected` state via {@link ui/Toggleable|Toggleable} unless set
 * directly.
 *
 * @class SwitchItem
 * @memberof agate/SwitchItem
 * @extends agate/SwitchItem.SwitchItemBase
 * @mixes agate/SwitchItem.SwitchItemDecorator
 * @ui
 * @public
 */
var SwitchItem = exports.SwitchItem = SwitchItemDecorator(SwitchItemBase);
var _default = exports["default"] = SwitchItem;