"use client";
import { jsxs as s, jsx as n } from "react/jsx-runtime";
import { Label as R } from "../shared/label.js";
import { RangeSlider as T } from "../shared/range-slider.js";
import { Select as i } from "../shared/select.js";
import { Tooltip as d } from "../shared/tooltip.js";
import { useAppSelector as U } from "../../hooks/use-app-selector.js";
import B from "../../hooks/use-debounce.js";
import { useSettings as M } from "../../hooks/use-settings.js";
import { getCurrentBreakpoint as X } from "../../../../../store/selectors.js";
import { Unit as m } from "../../types/style.js";
import { classNames as h } from "../../utils/index.js";
import { useState as A, useEffect as S } from "react";
import { BreakpointSelector as D } from "../shared/breakpoint-selector.js";
const G = [m.PX, m.PERCENTAGE, m.REM, m.EM], _ = ({
  min: x,
  max: g,
  step: v = 1,
  units: u = G,
  className: $,
  label: C,
  type: E,
  fieldName: a,
  mode: l,
  responsive: f = !1,
  ...j
}) => {
  const b = U(X), [t, y] = M(
    f && l ? `${a}.${b}.${l}` : f ? `${a}.${b}` : l ? `${a}.${l}` : a,
    E
  ), [e, p] = A(
    t ?? {
      value: void 0,
      unit: u[0] ?? m.PX
    }
  ), o = B(e, 400);
  S(() => {
    ((t == null ? void 0 : t.value) !== (o == null ? void 0 : o.value) || (t == null ? void 0 : t.unit) !== (o == null ? void 0 : o.unit)) && y(o);
  }, [o]), S(() => {
    ((t == null ? void 0 : t.value) !== (e == null ? void 0 : e.value) || (t == null ? void 0 : t.unit) !== (e == null ? void 0 : e.unit)) && p(t);
  }, [t]);
  const w = (r) => {
    p({ ...e, value: r });
  }, k = (r) => {
    p({
      ...e,
      unit: r
    });
  }, P = () => {
    switch ((t == null ? void 0 : t.unit) || m.PX) {
      case "px":
        return {
          min: x ?? 0,
          max: g ?? 1600
        };
      default:
        return {
          min: x ?? 0,
          max: g ?? 100
        };
    }
  }, { min: N, max: c } = P();
  return /* @__PURE__ */ s("div", { className: h("mt-4", $), children: [
    C && /* @__PURE__ */ s(R, { className: "mb-1.5 flex items-center gap-1", children: [
      C,
      " ",
      f && /* @__PURE__ */ n(D, {})
    ] }),
    /* @__PURE__ */ s("div", { className: h("flex gap-1.5"), ...j, children: [
      /* @__PURE__ */ n(
        T,
        {
          onValueChange: (r) => w(r[0]),
          value: [(e == null ? void 0 : e.value) ?? 0],
          step: v,
          max: c,
          min: N
        }
      ),
      /* @__PURE__ */ s(
        "div",
        {
          className: h(
            "flex h-7 items-center justify-between rounded-sm border text-slate-800"
          ),
          children: [
            /* @__PURE__ */ s(d, { children: [
              /* @__PURE__ */ n(d.Trigger, { children: /* @__PURE__ */ n(
                "input",
                {
                  onChange: (r) => w(r.target.value === "" ? void 0 : Number(r.target.value)),
                  value: (e == null ? void 0 : e.value) ?? "",
                  className: "remove-spinner w-[46px] rounded-sm border-0 bg-transparent p-0 pl-1.5 pt-[3px] text-[11px] leading-3 shadow-none outline-none focus:ring-0",
                  type: "number",
                  min: N,
                  max: c,
                  step: v
                }
              ) }),
              e != null && e.value && e.value > c ? /* @__PURE__ */ s(d.Content, { children: [
                "Value must be less than or equel to ",
                c
              ] }) : null
            ] }),
            /* @__PURE__ */ s(i, { onValueChange: k, value: (e == null ? void 0 : e.unit) || u[0], children: [
              /* @__PURE__ */ n(
                i.Trigger,
                {
                  className: "flex h-full w-7 items-center justify-center rounded-none rounded-r border-0 border-l p-0 text-[11px] leading-3 hover:bg-slate-300 focus:ring-0 focus:ring-offset-0",
                  chevronDown: !1,
                  children: /* @__PURE__ */ n(i.Value, {})
                }
              ),
              /* @__PURE__ */ n(i.Content, { alignOffset: -10, sideOffset: -60, className: "min-w-[38px] border-0", children: /* @__PURE__ */ n(i.Group, { children: u.map((r) => /* @__PURE__ */ n(
                i.Item,
                {
                  showCheck: !1,
                  value: r,
                  className: "flex items-center justify-center px-0 py-1.5 text-xs",
                  children: r
                },
                r
              )) }) })
            ] })
          ]
        }
      )
    ] })
  ] });
};
export {
  _ as SliderUnitControl
};
//# sourceMappingURL=slider-unit.control.js.map
