import { jsxs as E, jsx as l } from "react/jsx-runtime";
import M, { useCallback as D, useState as z, useMemo as N } from "react";
import { c as L } from "./index.CfM2L_w0.js";
import { l as H } from "./index.C1ZfizMq.js";
import { n as S } from "./index.B0wX8xO7.js";
import { D as C } from "./DropdownMenuItem.wz-AnckU.js";
import { a as j } from "./index.CfQlFjZU.js";
import { n as B } from "./index.dWlEA7uO.js";
import { T as O } from "./TextInputField.BXIFGIIj.js";
const V = "creator_container_eQkJS", k = "creator_upward_2sqxM", A = "creator_downward_gWKvk", F = "creator_container__empty_Z1O29", w = { container: V, upward: k, downward: A, container__empty: F }, R = (e, t) => e.filter((o) => (typeof o == "string" ? o : o.label)?.toLowerCase().includes(t.toLowerCase())), x = (e, t) => e.filter((o) => {
  const n = o, r = typeof o == "string" ? o : o.label, u = n.abbreviation, a = n.countryCode, s = n.countryName, i = n.timezoneCode, c = n.offsetLabel;
  return r?.toLowerCase().includes(t.toLowerCase()) || u.toLowerCase().includes(t.toLowerCase()) || i.toLowerCase().includes(t.toLowerCase()) || a.toLowerCase().includes(t.toLowerCase()) || s.toLowerCase().includes(t.toLowerCase()) || c.toLowerCase().includes(t.toLowerCase());
});
var I = /* @__PURE__ */ ((e) => (e.LABEL = "label", e.OBJECT = "object", e))(I || {});
const J = "No data", q = ({
  onChange: e,
  items: t,
  openDirection: o = "automatic",
  ...n
}) => {
  const r = M.useRef(null), u = (() => {
    if (r.current && o === "automatic") {
      const { innerHeight: a } = window, s = r.current?.clientHeight, c = (r.current.parentElement?.getBoundingClientRect()).bottom;
      return s + c < a ? "downward" : "upward";
    }
    return "downward";
  })();
  return {
    containerClassName: L(
      w.container,
      w[u],
      {
        [w.container__empty]: !t.length
      }
    ),
    classify: (a) => typeof a == "string" ? "label" : "object",
    change: D(
      (a, s) => {
        e && e(a, s);
      },
      [e]
    ),
    items: t,
    menuRef: r,
    ...n
  };
}, K = ({
  name: e,
  current: t,
  containerClassName: o,
  selectedItems: n,
  items: r,
  multiple: u,
  emptyLabel: a = J,
  change: s,
  hasSearch: i,
  searchOption: c = "default",
  searchPlaceholder: _,
  removeItemOnReselect: p,
  menuRef: b,
  ...g
}) => {
  const [d, y] = z(""), m = N(() => {
    switch (c) {
      case "timezone":
        return x(r, d);
      case "default":
      default:
        return R(r, d);
    }
  }, [r, c, d]), h = (f) => {
    const v = f.target.value || "";
    y(v);
  };
  return /* @__PURE__ */ E(
    "ul",
    {
      className: L(o, {
        [w.container__empty]: !m.length
      }),
      role: "listbox",
      ref: b,
      ...g,
      children: [
        /* @__PURE__ */ l(
          S,
          {
            value: i,
            then: /* @__PURE__ */ l(
              O,
              {
                prefixIcon: /* @__PURE__ */ l(B, { size: 24 }),
                placeholder: _ || "Search",
                onChange: h,
                value: d
              }
            )
          }
        ),
        /* @__PURE__ */ l(
          H,
          {
            values: m,
            layout: (f) => /* @__PURE__ */ l(
              C,
              {
                name: e,
                item: f,
                selectedItems: n,
                multiple: u,
                current: t,
                onChange: s,
                removeItemOnReselect: p
              }
            ),
            otherwise: /* @__PURE__ */ l(
              C,
              {
                name: e,
                item: {
                  value: a,
                  disabled: !0
                },
                onChange: s,
                removeItemOnReselect: p
              }
            )
          }
        )
      ]
    }
  );
}, T = j(K, q);
export {
  I as D,
  J as a,
  K as b,
  T as c,
  q as u
};
