"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SwatchButtonDecorator = exports.SwatchButtonBase = exports.SwatchButton = exports["default"] = void 0;

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

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

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

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

var _Button = require("../Button");

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

var _SwatchButtonModule = _interopRequireDefault(require("./SwatchButton.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; }

/**
 * A swatch component which sets-up the component's structure.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within [SwatchButton]{@link agate/ColorPicker.SwatchButton}.
 *
 * @class SwatchButtonBase
 * @memberof agate/ColorPicker
 * @extends agate/Button.ButtonBase
 * @ui
 * @public
 */
var SwatchButtonBase = (0, _kind["default"])({
  name: 'SwatchButton',
  propTypes:
  /** @lends agate/ColorPicker.SwatchButtonBase.prototype */
  {
    /**
     * The color of the swatch if the `color` prop is not set.
     *
     * The value should take the format of a HEX color. Ex: `#ffcc00` or `#3467af`
     *
     * @type {Object}
     * @public
     */
    children: _propTypes["default"].object,

    /**
     * The color of the swatch.
     *
     * The value should take the format of a HEX color. Ex: `#ffcc00` or `#3467af`
     *
     * @type {String}
     * @public
     */
    color: _propTypes["default"].string,

    /**
     * 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:
     *
     * * `swatchButton` - The root class name
     * * `colorSwatch` - The node that displays the chosen color. The current value is applied
     * 		as a background-color to this element.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,

    /**
     * Callback method with a payload containing the `value` that was just selected.
     *
     * @type {Function}
     * @public
     */
    onClick: _propTypes["default"].func
  },
  styles: {
    css: _SwatchButtonModule["default"],
    className: 'swatchButton',
    publicClassNames: ['swatchButton', 'colorSwatch']
  },
  handlers: {
    onClick: function onClick(ev, _ref) {
      var children = _ref.children,
          color = _ref.color,
          _onClick = _ref.onClick;

      if (_onClick) {
        _onClick({
          color: color || children
        });
      }
    }
  },
  computed: {
    colorSwatchStyle: function colorSwatchStyle(_ref2) {
      var children = _ref2.children,
          color = _ref2.color;
      return {
        backgroundColor: color ? color : children
      };
    }
  },
  render: function render(_ref3) {
    var colorSwatchStyle = _ref3.colorSwatchStyle,
        css = _ref3.css,
        rest = _objectWithoutProperties(_ref3, ["colorSwatchStyle", "css"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonBase, _objectSpread(_objectSpread({
      "aria-label": colorSwatchStyle.backgroundColor
    }, rest), {}, {
      css: css,
      minWidth: false,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: css.colorSwatch,
        style: colorSwatchStyle
      })
    }));
  }
});
/**
 * Applies Agate specific behaviors to [SwatchButtonBase]{@link agate/ColorPicker.SwatchButtonBase}.
 *
 * @hoc
 * @memberof agate/ColorPicker
 * @mixes agate/Button.ButtonDecorator
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.SwatchButtonBase = SwatchButtonBase;
var SwatchButtonDecorator = (0, _compose["default"])(_Button.ButtonDecorator, _Skinnable["default"]);
/**
 * A color picker swatch button component.
 *
 * @class SwatchButton
 * @memberof agate/ColorPicker
 * @extends agate/ColorPicker.SwatchButtonBase
 * @mixes agate/ColorPicker.SwatchButtonDecorator
 * @ui
 * @public
 */

exports.SwatchButtonDecorator = SwatchButtonDecorator;
var SwatchButton = SwatchButtonDecorator(SwatchButtonBase);
exports.SwatchButton = SwatchButton;
var _default = SwatchButton;
exports["default"] = _default;