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