var __assign = this && this.__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { Swatch } from 'react-color/lib/components/common';
import { useEvent, useHover } from 'react-use';
import classNames from 'classnames';
import { prefixCls } from "./constant";

var CircleSwatch = function CircleSwatch(_a) {
  var onDelete = _a.onDelete,
      index = _a.index,
      color = _a.color,
      onClick = _a.onClick,
      active = _a.active,
      onSwatchHover = _a.onSwatchHover;
  var ref = React.useRef(null);
  var element = React.useMemo(function () {
    return _jsx("div", __assign({
      className: prefixCls + "-circle-swatch"
    }, {
      children: _jsx(Swatch, {
        color: color,
        onClick: onClick,
        onHover: onSwatchHover
      }, void 0)
    }), void 0);
  }, [color, onClick, onSwatchHover]);
  var handleKeyup = React.useCallback(function (_a) {
    var key = _a.key;

    if (key === 'Backspace' && onDelete) {
      onDelete(index);
    }
  }, [index, onDelete]);
  useEvent('keydown', handleKeyup, ref.current, {});

  var _b = useHover(element),
      hoverable = _b[0],
      hovered = _b[1];

  var wrapCls = classNames(prefixCls + "-circle-swatch-wrap", {
    hovered: hovered,
    active: active
  });
  return _jsx("div", __assign({
    ref: ref,
    className: wrapCls
  }, {
    children: hoverable
  }), void 0);
};

CircleSwatch.displayName = 'CircleSwatch';
export default CircleSwatch;
var CircleSwatchMemo = /*#__PURE__*/React.memo(CircleSwatch);
CircleSwatchMemo.displayName = 'CircleSwatchMemo';
export { CircleSwatchMemo };

