import { C as t, a as l, Z as g, c as f, f as v, t as E } from "./css-fOi2x-55.js";
import { j as c } from "./jsx-runtime-NmMXPjeo.js";
import { h as T, i as A, u as C, j as H, k as x, l as M, B as N, e as O, m as R } from "./Toggle-E-Bsru_F.js";
import { useCallback as L } from "react";
import "./Center-c6LFuqp8.js";
import "./aggregator-BIN9LAqD.js";
import "react-hook-form";
const k = ({ value: r, onChange: o, ...p }) => {
  const n = (e) => {
    e.hex === "transparent" && o(g), o(new l(e.hex, e.rgb.a));
  };
  return /* @__PURE__ */ c.jsx(
    T,
    {
      className: t.B("color-picker"),
      color: new l(r).hex,
      onChange: n,
      presetColors: [],
      ...p
    }
  );
}, u = "color", Z = ({
  value: r,
  onChange: o,
  className: p,
  size: n = "medium",
  onVisibleChange: e,
  initialVisible: h,
  draggable: S = !0,
  ...y
}) => {
  const { visible: j, open: w, close: b } = A({ onVisibleChange: e, initialVisible: h }), D = C().colors.gray.l0, s = new l(r), B = H(), m = L(
    ({ items: i }) => {
      const [a] = x(u, i);
      return a != null && a.key !== s.hex;
    },
    [s.hex]
  ), { startDrag: P, ..._ } = M({
    type: "Color.Swatch",
    onDrop: ({ items: i }) => {
      const a = x(u, i);
      return i.length > 0 && (o == null || o(new l(a[0].key))), a;
    },
    canDrop: m
  }), d = /* @__PURE__ */ c.jsx(
    N,
    {
      className: t(
        t.B("color-swatch"),
        t.size(n),
        s.contrast(D) > 1.5 && s.a > 0.5 && t.M("no-border"),
        t.dropRegion(m(B)),
        p
      ),
      draggable: S,
      onDragStart: () => P([{ type: u, key: s.hex }]),
      style: { backgroundColor: f(r) },
      variant: "text",
      onClick: w,
      size: n,
      tooltip: o != null ? /* @__PURE__ */ c.jsx(O, { level: "small", children: "Click to change color" }) : void 0,
      ..._,
      ...y
    }
  );
  return o == null ? d : /* @__PURE__ */ c.jsxs(
    R,
    {
      close: b,
      visible: j,
      className: t.BE("color-swatch", "dropdown"),
      keepMounted: !1,
      variant: "floating",
      children: [
        d,
        /* @__PURE__ */ c.jsx(k, { value: r, onChange: o })
      ]
    }
  );
}, I = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  Color: l,
  Picker: k,
  Swatch: Z,
  ZERO: g,
  cssString: f,
  fromHSLA: v,
  toHex: E
}, Symbol.toStringTag, { value: "Module" }));
export {
  Z as S,
  I as e
};
//# sourceMappingURL=external-s-Kna6s0.js.map
