import { U as reactExports, L as jsxRuntimeExports } from "./server-DSC_YmUp.js";
import { r as createLucideIcon, l as cn, e as Presence, f as Primitive, K as useControllableState, J as useComposedRefs, m as composeEventHandlers, T as useSize, q as createContextScope, C as Check, B as Button, z as supabase, E as toast, G as useAuth, S as useNavigate, L as Link, b as ChevronRight } from "./router-CEZm8MTA.js";
import { C as Card } from "./card-CdzUIPcf.js";
import { R as Root, t as Trigger, n as Portal, m as Content, l as Close, X, r as Title, O as Overlay, D as Description, i as Avatar, k as AvatarImage, j as AvatarFallback, A as AlertDialog, h as AlertDialogTrigger, s as Trash2, c as AlertDialogContent, f as AlertDialogHeader, g as AlertDialogTitle, d as AlertDialogDescription, e as AlertDialogFooter, b as AlertDialogCancel, a as AlertDialogAction, T as Tabs, p as TabsList, q as TabsTrigger, o as TabsContent, C as Chat, P as Plus } from "./tabs-BcrBvEup.js";
import { I as Input, L as Label } from "./label-gF41I2IG.js";
import { u as usePrevious } from "./index-2u08pLu1.js";
import { U as Users } from "./users-LIPb0en-.js";
import { A as ArrowLeft } from "./arrow-left-CNLv9jsf.js";
import { M as MessageCircle } from "./utensils-Cya-B9wL.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
const __iconNode$3 = [
  ["path", { d: "m21 16-4 4-4-4", key: "f6ql7i" }],
  ["path", { d: "M17 20V4", key: "1ejh1v" }],
  ["path", { d: "m3 8 4-4 4 4", key: "11wl7u" }],
  ["path", { d: "M7 4v16", key: "1glfcx" }]
];
const ArrowUpDown = createLucideIcon("arrow-up-down", __iconNode$3);
const __iconNode$2 = [
  ["polyline", { points: "22 12 16 12 14 15 10 15 8 12 2 12", key: "o97t9d" }],
  [
    "path",
    {
      d: "M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",
      key: "oot6mr"
    }
  ]
];
const Inbox = createLucideIcon("inbox", __iconNode$2);
const __iconNode$1 = [
  ["path", { d: "m21 21-4.34-4.34", key: "14j7rj" }],
  ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }]
];
const Search = createLucideIcon("search", __iconNode$1);
const __iconNode = [
  ["path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", key: "1yyitq" }],
  ["circle", { cx: "9", cy: "7", r: "4", key: "nufk8" }],
  ["line", { x1: "19", x2: "19", y1: "8", y2: "14", key: "1bvyxn" }],
  ["line", { x1: "22", x2: "16", y1: "11", y2: "11", key: "1shjgl" }]
];
const UserPlus = createLucideIcon("user-plus", __iconNode);
const Dialog = Root;
const DialogTrigger = Trigger;
const DialogPortal = Portal;
const DialogOverlay = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  Overlay,
  {
    ref,
    className: cn(
      "fixed inset-0 z-50 bg-black/80  data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
      className
    ),
    ...props
  }
));
DialogOverlay.displayName = Overlay.displayName;
const DialogContent = reactExports.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogPortal, { children: [
  /* @__PURE__ */ jsxRuntimeExports.jsx(DialogOverlay, {}),
  /* @__PURE__ */ jsxRuntimeExports.jsxs(
    Content,
    {
      ref,
      className: cn(
        "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
        className
      ),
      ...props,
      children: [
        children,
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "h-4 w-4" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sr-only", children: "Close" })
        ] })
      ]
    }
  )
] }));
DialogContent.displayName = Content.displayName;
const DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: cn("flex flex-col space-y-1.5 text-center sm:text-left", className), ...props });
DialogHeader.displayName = "DialogHeader";
const DialogFooter = ({ className, ...props }) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  "div",
  {
    className: cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className),
    ...props
  }
);
DialogFooter.displayName = "DialogFooter";
const DialogTitle = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  Title,
  {
    ref,
    className: cn("text-lg font-semibold leading-none tracking-tight", className),
    ...props
  }
));
DialogTitle.displayName = Title.displayName;
const DialogDescription = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  Description,
  {
    ref,
    className: cn("text-sm text-muted-foreground", className),
    ...props
  }
));
DialogDescription.displayName = Description.displayName;
var CHECKBOX_NAME = "Checkbox";
var [createCheckboxContext] = createContextScope(CHECKBOX_NAME);
var [CheckboxProviderImpl, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
function CheckboxProvider(props) {
  const {
    __scopeCheckbox,
    checked: checkedProp,
    children,
    defaultChecked,
    disabled,
    form,
    name,
    onCheckedChange,
    required,
    value = "on",
    // @ts-expect-error
    internal_do_not_use_render
  } = props;
  const [checked, setChecked] = useControllableState({
    prop: checkedProp,
    defaultProp: defaultChecked ?? false,
    onChange: onCheckedChange,
    caller: CHECKBOX_NAME
  });
  const [control, setControl] = reactExports.useState(null);
  const [bubbleInput, setBubbleInput] = reactExports.useState(null);
  const hasConsumerStoppedPropagationRef = reactExports.useRef(false);
  const isFormControl = control ? !!form || !!control.closest("form") : (
    // We set this to true by default so that events bubble to forms without JS (SSR)
    true
  );
  const context = {
    checked,
    disabled,
    setChecked,
    control,
    setControl,
    name,
    form,
    value,
    hasConsumerStoppedPropagationRef,
    required,
    defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,
    isFormControl,
    bubbleInput,
    setBubbleInput
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    CheckboxProviderImpl,
    {
      scope: __scopeCheckbox,
      ...context,
      children: isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children
    }
  );
}
var TRIGGER_NAME = "CheckboxTrigger";
var CheckboxTrigger = reactExports.forwardRef(
  ({ __scopeCheckbox, onKeyDown, onClick, ...checkboxProps }, forwardedRef) => {
    const {
      control,
      value,
      disabled,
      checked,
      required,
      setControl,
      setChecked,
      hasConsumerStoppedPropagationRef,
      isFormControl,
      bubbleInput
    } = useCheckboxContext(TRIGGER_NAME, __scopeCheckbox);
    const composedRefs = useComposedRefs(forwardedRef, setControl);
    const initialCheckedStateRef = reactExports.useRef(checked);
    reactExports.useEffect(() => {
      const form = control?.form;
      if (form) {
        const reset = () => setChecked(initialCheckedStateRef.current);
        form.addEventListener("reset", reset);
        return () => form.removeEventListener("reset", reset);
      }
    }, [control, setChecked]);
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      Primitive.button,
      {
        type: "button",
        role: "checkbox",
        "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
        "aria-required": required,
        "data-state": getState(checked),
        "data-disabled": disabled ? "" : void 0,
        disabled,
        value,
        ...checkboxProps,
        ref: composedRefs,
        onKeyDown: composeEventHandlers(onKeyDown, (event) => {
          if (event.key === "Enter") event.preventDefault();
        }),
        onClick: composeEventHandlers(onClick, (event) => {
          setChecked((prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked);
          if (bubbleInput && isFormControl) {
            hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
            if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
          }
        })
      }
    );
  }
);
CheckboxTrigger.displayName = TRIGGER_NAME;
var Checkbox$1 = reactExports.forwardRef(
  (props, forwardedRef) => {
    const {
      __scopeCheckbox,
      name,
      checked,
      defaultChecked,
      required,
      disabled,
      value,
      onCheckedChange,
      form,
      ...checkboxProps
    } = props;
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      CheckboxProvider,
      {
        __scopeCheckbox,
        checked,
        defaultChecked,
        disabled,
        required,
        onCheckedChange,
        name,
        form,
        value,
        internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            CheckboxTrigger,
            {
              ...checkboxProps,
              ref: forwardedRef,
              __scopeCheckbox
            }
          ),
          isFormControl && /* @__PURE__ */ jsxRuntimeExports.jsx(
            CheckboxBubbleInput,
            {
              __scopeCheckbox
            }
          )
        ] })
      }
    );
  }
);
Checkbox$1.displayName = CHECKBOX_NAME;
var INDICATOR_NAME = "CheckboxIndicator";
var CheckboxIndicator = reactExports.forwardRef(
  (props, forwardedRef) => {
    const { __scopeCheckbox, forceMount, ...indicatorProps } = props;
    const context = useCheckboxContext(INDICATOR_NAME, __scopeCheckbox);
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      Presence,
      {
        present: forceMount || isIndeterminate(context.checked) || context.checked === true,
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(
          Primitive.span,
          {
            "data-state": getState(context.checked),
            "data-disabled": context.disabled ? "" : void 0,
            ...indicatorProps,
            ref: forwardedRef,
            style: { pointerEvents: "none", ...props.style }
          }
        )
      }
    );
  }
);
CheckboxIndicator.displayName = INDICATOR_NAME;
var BUBBLE_INPUT_NAME = "CheckboxBubbleInput";
var CheckboxBubbleInput = reactExports.forwardRef(
  ({ __scopeCheckbox, ...props }, forwardedRef) => {
    const {
      control,
      hasConsumerStoppedPropagationRef,
      checked,
      defaultChecked,
      required,
      disabled,
      name,
      value,
      form,
      bubbleInput,
      setBubbleInput
    } = useCheckboxContext(BUBBLE_INPUT_NAME, __scopeCheckbox);
    const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);
    const prevChecked = usePrevious(checked);
    const controlSize = useSize(control);
    reactExports.useEffect(() => {
      const input = bubbleInput;
      if (!input) return;
      const inputProto = window.HTMLInputElement.prototype;
      const descriptor = Object.getOwnPropertyDescriptor(
        inputProto,
        "checked"
      );
      const setChecked = descriptor.set;
      const bubbles = !hasConsumerStoppedPropagationRef.current;
      if (prevChecked !== checked && setChecked) {
        const event = new Event("click", { bubbles });
        input.indeterminate = isIndeterminate(checked);
        setChecked.call(input, isIndeterminate(checked) ? false : checked);
        input.dispatchEvent(event);
      }
    }, [bubbleInput, prevChecked, checked, hasConsumerStoppedPropagationRef]);
    const defaultCheckedRef = reactExports.useRef(isIndeterminate(checked) ? false : checked);
    return /* @__PURE__ */ jsxRuntimeExports.jsx(
      Primitive.input,
      {
        type: "checkbox",
        "aria-hidden": true,
        defaultChecked: defaultChecked ?? defaultCheckedRef.current,
        required,
        disabled,
        name,
        value,
        form,
        ...props,
        tabIndex: -1,
        ref: composedRefs,
        style: {
          ...props.style,
          ...controlSize,
          position: "absolute",
          pointerEvents: "none",
          opacity: 0,
          margin: 0,
          // We transform because the input is absolutely positioned but we have
          // rendered it **after** the button. This pulls it back to sit on top
          // of the button.
          transform: "translateX(-100%)"
        }
      }
    );
  }
);
CheckboxBubbleInput.displayName = BUBBLE_INPUT_NAME;
function isFunction(value) {
  return typeof value === "function";
}
function isIndeterminate(checked) {
  return checked === "indeterminate";
}
function getState(checked) {
  return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
}
const Checkbox = reactExports.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntimeExports.jsx(
  Checkbox$1,
  {
    ref,
    className: cn(
      "grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
      className
    ),
    ...props,
    children: /* @__PURE__ */ jsxRuntimeExports.jsx(CheckboxIndicator, { className: cn("grid place-content-center text-current"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Check, { className: "h-4 w-4" }) })
  }
));
Checkbox.displayName = Checkbox$1.displayName;
function GroupMembersPanel({ groupId }) {
  const [members, setMembers] = reactExports.useState([]);
  const [profiles, setProfiles] = reactExports.useState({});
  const [allClients, setAllClients] = reactExports.useState([]);
  const [adminIds, setAdminIds] = reactExports.useState(/* @__PURE__ */ new Set());
  const [open, setOpen] = reactExports.useState(false);
  const [picked, setPicked] = reactExports.useState(/* @__PURE__ */ new Set());
  const [search, setSearch] = reactExports.useState("");
  const [adding, setAdding] = reactExports.useState(false);
  const load = async () => {
    const [{ data: ms }, { data: ps }, { data: roles }] = await Promise.all([
      supabase.from("chat_group_members").select("*").eq("group_id", groupId),
      supabase.from("profiles").select("id,full_name,nickname,avatar_url"),
      supabase.from("user_roles").select("user_id,role")
    ]);
    const memberList = ms ?? [];
    setMembers(memberList);
    const allProfiles = ps ?? [];
    setProfiles(Object.fromEntries(allProfiles.map((p) => [p.id, p])));
    const admins = new Set(
      (roles ?? []).filter((r) => r.role === "admin").map((r) => r.user_id)
    );
    setAdminIds(admins);
    setAllClients(allProfiles.filter((p) => !admins.has(p.id)));
  };
  reactExports.useEffect(() => {
    load();
  }, [groupId]);
  const memberIds = new Set(members.map((m) => m.user_id));
  const candidates = allClients.filter(
    (c) => !memberIds.has(c.id) && (search ? `${c.nickname ?? ""} ${c.full_name ?? ""}`.toLowerCase().includes(search.toLowerCase()) : true)
  );
  const addMembers = async () => {
    if (picked.size === 0) {
      toast.error("Selectează cel puțin un utilizator");
      return;
    }
    setAdding(true);
    const rows = Array.from(picked).map((uid) => ({
      group_id: groupId,
      user_id: uid,
      role: "member"
    }));
    const { error } = await supabase.from("chat_group_members").insert(rows);
    setAdding(false);
    if (error) {
      toast.error(error.message);
      return;
    }
    toast.success(`${picked.size} membri adăugați`);
    setPicked(/* @__PURE__ */ new Set());
    setSearch("");
    setOpen(false);
    load();
  };
  const remove = async (m) => {
    const { error } = await supabase.from("chat_group_members").delete().eq("id", m.id);
    if (error) toast.error(error.message);
    else {
      toast.success("Membru eliminat");
      load();
    }
  };
  const label = (p) => p ? p.nickname ? `${p.nickname} (${p.full_name || "—"})` : p.full_name || "(fără nume)" : "…";
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-3 sm:p-4 rounded-2xl shadow-[var(--shadow-card)] space-y-3", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "font-display font-semibold flex items-center gap-2 tracking-tight", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "h-4 w-4 text-primary" }),
        " Membri (",
        members.length,
        ")"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(
        Dialog,
        {
          open,
          onOpenChange: (v) => {
            setOpen(v);
            if (!v) {
              setPicked(/* @__PURE__ */ new Set());
              setSearch("");
            }
          },
          children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { size: "sm", className: "rounded-full", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(UserPlus, { className: "h-4 w-4 mr-1" }),
              " Adaugă"
            ] }) }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTitle, { children: "Adaugă membri în grup" }) }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
                /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx(Search, { className: "h-4 w-4 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground" }),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(
                    Input,
                    {
                      className: "pl-8",
                      placeholder: "Caută după nume sau poreclă",
                      value: search,
                      onChange: (e) => setSearch(e.target.value)
                    }
                  )
                ] }),
                /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border rounded-md max-h-72 overflow-y-auto divide-y", children: [
                  candidates.map((c) => {
                    const checked = picked.has(c.id);
                    return /* @__PURE__ */ jsxRuntimeExports.jsxs(
                      "label",
                      {
                        className: "flex items-center gap-2 p-2 cursor-pointer hover:bg-accent/10",
                        children: [
                          /* @__PURE__ */ jsxRuntimeExports.jsx(
                            Checkbox,
                            {
                              checked,
                              onCheckedChange: (v) => {
                                setPicked((p) => {
                                  const n = new Set(p);
                                  if (v) n.add(c.id);
                                  else n.delete(c.id);
                                  return n;
                                });
                              }
                            }
                          ),
                          /* @__PURE__ */ jsxRuntimeExports.jsxs(Avatar, { className: "h-7 w-7", children: [
                            c.avatar_url && /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarImage, { src: c.avatar_url }),
                            /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarFallback, { className: "text-[10px]", children: (c.nickname || c.full_name || "?").slice(0, 2).toUpperCase() })
                          ] }),
                          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm truncate", children: label(c) })
                        ]
                      },
                      c.id
                    );
                  }),
                  candidates.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "p-3 text-sm text-muted-foreground", children: "Niciun utilizator disponibil." })
                ] })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(DialogFooter, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                Button,
                {
                  onClick: addMembers,
                  disabled: adding || picked.size === 0,
                  className: "rounded-full",
                  children: adding ? "Se adaugă…" : `Adaugă ${picked.size || ""}`.trim()
                }
              ) })
            ] })
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "divide-y border rounded-xl", children: [
      members.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "p-3 text-sm text-muted-foreground", children: "Niciun membru." }),
      members.map((m) => {
        const p = profiles[m.user_id];
        const isAdmin = m.role === "admin" || adminIds.has(m.user_id);
        return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 p-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Avatar, { className: "h-8 w-8", children: [
            p?.avatar_url && /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarImage, { src: p.avatar_url }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarFallback, { className: "text-[10px]", children: (p?.nickname || p?.full_name || "?").slice(0, 2).toUpperCase() })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium truncate", children: label(p) }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-[11px] text-muted-foreground", children: [
              isAdmin ? "Admin" : "Membru",
              " · din",
              " ",
              new Date(m.joined_at).toLocaleDateString("ro-RO")
            ] })
          ] }),
          !isAdmin && /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialog, { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "ghost", size: "icon", title: "Elimină din grup", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Trash2, { className: "h-4 w-4 text-destructive" }) }) }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogContent, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogHeader, { children: [
                /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogTitle, { children: [
                  "Elimini „",
                  label(p),
                  '" din grup?'
                ] }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDialogDescription, { children: "Va pierde accesul la conversațiile și mesajele din acest grup, dar contul rămâne activ." })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogFooter, { children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDialogCancel, { children: "Anulează" }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(
                  AlertDialogAction,
                  {
                    onClick: () => remove(m),
                    className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
                    children: "Elimină"
                  }
                )
              ] })
            ] })
          ] })
        ] }, m.id);
      })
    ] })
  ] });
}
function GroupsManager({ currentUserId }) {
  const [groups, setGroups] = reactExports.useState([]);
  const [clients, setClients] = reactExports.useState([]);
  const [open, setOpen] = reactExports.useState(false);
  const [name, setName] = reactExports.useState("");
  const [picked, setPicked] = reactExports.useState(/* @__PURE__ */ new Set());
  const [activeGroup, setActiveGroup] = reactExports.useState(null);
  const [creating, setCreating] = reactExports.useState(false);
  const [memberCounts, setMemberCounts] = reactExports.useState({});
  const load = async () => {
    const [{ data: gs }, { data: profiles }, { data: roles }, { data: members }] = await Promise.all([
      supabase.from("chat_groups").select("*").order("created_at", { ascending: false }),
      supabase.from("profiles").select("id,full_name,nickname,avatar_url"),
      supabase.from("user_roles").select("user_id,role"),
      supabase.from("chat_group_members").select("group_id,user_id")
    ]);
    const adminIds = new Set(
      (roles ?? []).filter((r) => r.role === "admin").map((r) => r.user_id)
    );
    setGroups(gs ?? []);
    setClients((profiles ?? []).filter((p) => !adminIds.has(p.id)));
    const counts = {};
    for (const m of members ?? []) counts[m.group_id] = (counts[m.group_id] || 0) + 1;
    setMemberCounts(counts);
  };
  reactExports.useEffect(() => {
    load();
  }, []);
  const create = async () => {
    if (!name.trim()) {
      toast.error("Adaugă un nume");
      return;
    }
    if (picked.size === 0) {
      toast.error("Selectează cel puțin un membru");
      return;
    }
    setCreating(true);
    const { data: g, error } = await supabase.from("chat_groups").insert({ name: name.trim(), created_by: currentUserId }).select().single();
    if (error || !g) {
      toast.error(error?.message || "Eroare");
      setCreating(false);
      return;
    }
    const rows = [
      { group_id: g.id, user_id: currentUserId, role: "admin" },
      ...Array.from(picked).map((uid) => ({
        group_id: g.id,
        user_id: uid,
        role: "member"
      }))
    ];
    const { error: mErr } = await supabase.from("chat_group_members").insert(rows);
    setCreating(false);
    if (mErr) {
      toast.error(mErr.message);
      return;
    }
    toast.success("Grup creat");
    setOpen(false);
    setName("");
    setPicked(/* @__PURE__ */ new Set());
    load();
  };
  const removeGroup = async (id) => {
    const { error } = await supabase.from("chat_groups").delete().eq("id", id);
    if (error) toast.error(error.message);
    else {
      toast.success("Grup șters");
      load();
      if (activeGroup?.id === id) setActiveGroup(null);
    }
  };
  if (activeGroup) {
    return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(
        Button,
        {
          variant: "ghost",
          size: "sm",
          onClick: () => {
            setActiveGroup(null);
            load();
          },
          className: "rounded-full",
          children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowLeft, { className: "h-4 w-4 mr-1" }),
            " Înapoi la grupuri"
          ]
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "font-display text-2xl font-bold tracking-tight", children: activeGroup.name }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Tabs, { defaultValue: "chat", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsList, { className: "bg-card p-1.5 rounded-2xl border shadow-[var(--shadow-card)]", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(TabsTrigger, { value: "chat", className: "rounded-xl", children: "Chat" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(TabsTrigger, { value: "members", className: "rounded-xl", children: "Membri" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TabsContent, { value: "chat", className: "mt-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Chat, { groupId: activeGroup.id, currentUserId, isAdmin: true }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TabsContent, { value: "members", className: "mt-3", children: /* @__PURE__ */ jsxRuntimeExports.jsx(GroupMembersPanel, { groupId: activeGroup.id }) })
      ] })
    ] });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("h2", { className: "font-display text-lg font-semibold tracking-tight flex items-center gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "h-5 w-5 text-primary" }),
        " Grupuri (",
        groups.length,
        ")"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Dialog, { open, onOpenChange: setOpen, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { size: "sm", className: "rounded-full", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { className: "h-4 w-4 mr-1" }),
          " Grup nou"
        ] }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTitle, { children: "Creează grup nou" }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { children: "Nume grup" }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                Input,
                {
                  value: name,
                  onChange: (e) => setName(e.target.value),
                  placeholder: "ex: Cutting Squad"
                }
              )
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs(Label, { children: [
                "Membri (",
                picked.size,
                " aleși)"
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "border rounded-md max-h-64 overflow-y-auto divide-y", children: [
                clients.map((c) => {
                  const checked = picked.has(c.id);
                  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
                    "label",
                    {
                      className: "flex items-center gap-2 p-2 cursor-pointer hover:bg-accent/10",
                      children: [
                        /* @__PURE__ */ jsxRuntimeExports.jsx(
                          Checkbox,
                          {
                            checked,
                            onCheckedChange: (v) => {
                              setPicked((p) => {
                                const n = new Set(p);
                                if (v) n.add(c.id);
                                else n.delete(c.id);
                                return n;
                              });
                            }
                          }
                        ),
                        /* @__PURE__ */ jsxRuntimeExports.jsxs(Avatar, { className: "h-7 w-7", children: [
                          c.avatar_url && /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarImage, { src: c.avatar_url }),
                          /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarFallback, { className: "text-[10px]", children: (c.nickname || c.full_name || "?").slice(0, 2).toUpperCase() })
                        ] }),
                        /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm truncate", children: c.nickname ? `${c.nickname} (${c.full_name || "—"})` : c.full_name || "(fără nume)" })
                      ]
                    },
                    c.id
                  );
                }),
                clients.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "p-3 text-sm text-muted-foreground", children: "Niciun client." })
              ] })
            ] })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(DialogFooter, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: create, disabled: creating, className: "rounded-full", children: creating ? "Se creează…" : "Creează grup" }) })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-2", children: [
      groups.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-10 rounded-2xl text-center", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "h-10 w-10 mx-auto text-muted-foreground/40 mb-3" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Niciun grup încă. Creează primul tău grup pentru un challenge sau o discuție colectivă." })
      ] }),
      groups.map((g) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
        Card,
        {
          className: "p-3 rounded-2xl shadow-[var(--shadow-card)] flex items-center gap-3 hover:shadow-soft hover:-translate-y-0.5 transition-all cursor-pointer",
          onClick: () => setActiveGroup(g),
          children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs(Avatar, { className: "h-11 w-11", children: [
              g.avatar_url && /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarImage, { src: g.avatar_url }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarFallback, { className: "bg-primary/15 text-primary font-display font-bold", children: g.name.slice(0, 2).toUpperCase() })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-display font-semibold truncate", children: g.name }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-muted-foreground font-num", children: [
                memberCounts[g.id] || 0,
                " membri"
              ] })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialog, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                Button,
                {
                  variant: "ghost",
                  size: "icon",
                  onClick: (e) => e.stopPropagation(),
                  "aria-label": "Șterge grupul",
                  children: /* @__PURE__ */ jsxRuntimeExports.jsx(Trash2, { className: "h-4 w-4 text-destructive" })
                }
              ) }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogContent, { onClick: (e) => e.stopPropagation(), children: [
                /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogHeader, { children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogTitle, { children: [
                    "Ștergi grupul „",
                    g.name,
                    '"?'
                  ] }),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDialogDescription, { children: "Toate mesajele și asocierile de membri din acest grup vor fi șterse definitiv. Acțiunea nu poate fi anulată." })
                ] }),
                /* @__PURE__ */ jsxRuntimeExports.jsxs(AlertDialogFooter, { children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDialogCancel, { children: "Anulează" }),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(
                    AlertDialogAction,
                    {
                      onClick: () => removeGroup(g.id),
                      className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
                      children: "Șterge grup"
                    }
                  )
                ] })
              ] })
            ] })
          ]
        },
        g.id
      ))
    ] })
  ] });
}
function AdminHome() {
  const {
    user,
    loading,
    isAdmin
  } = useAuth();
  const navigate = useNavigate();
  const [clients, setClients] = reactExports.useState([]);
  const [query, setQuery] = reactExports.useState("");
  const [sortBy, setSortBy] = reactExports.useState("unread");
  const [loaded, setLoaded] = reactExports.useState(false);
  reactExports.useEffect(() => {
    if (!loading && !user) navigate({
      to: "/auth"
    });
    if (!loading && user && !isAdmin) navigate({
      to: "/dashboard"
    });
  }, [user, loading, isAdmin, navigate]);
  reactExports.useEffect(() => {
    if (!isAdmin || !user) return;
    const load = async () => {
      const [{
        data: profiles
      }, {
        data: roles
      }, {
        data: weights
      }, {
        data: msgs
      }] = await Promise.all([supabase.from("profiles").select("id,full_name,nickname,avatar_url,email"), supabase.from("user_roles").select("user_id,role"), supabase.from("weight_entries").select("user_id,weight_kg,recorded_at").order("recorded_at", {
        ascending: false
      }), supabase.from("messages").select("client_id,sender_id,read_at,group_id").is("read_at", null).is("group_id", null)]);
      const adminIds = new Set((roles ?? []).filter((r) => r.role === "admin").map((r) => r.user_id));
      const list = (profiles ?? []).filter((p) => !adminIds.has(p.id)).map((p) => {
        const userWeights = (weights ?? []).filter((w) => w.user_id === p.id);
        const unread = (msgs ?? []).filter((m) => m.client_id === p.id && m.sender_id !== user.id).length;
        return {
          id: p.id,
          full_name: p.full_name,
          nickname: p.nickname,
          avatar_url: p.avatar_url,
          email: p.email,
          latest_weight: userWeights[0]?.weight_kg ?? null,
          entries: userWeights.length,
          unread
        };
      });
      setClients(list);
      setLoaded(true);
    };
    load();
    const ch = supabase.channel("admin-unread").on("postgres_changes", {
      event: "*",
      schema: "public",
      table: "messages"
    }, () => load()).subscribe();
    return () => {
      supabase.removeChannel(ch);
    };
  }, [isAdmin, user]);
  const filtered = reactExports.useMemo(() => {
    const q = query.trim().toLowerCase();
    const matches = q ? clients.filter((c) => {
      const hay = [c.full_name, c.nickname, c.email].filter(Boolean).join(" ").toLowerCase();
      return hay.includes(q);
    }) : clients;
    const sorted = [...matches];
    if (sortBy === "unread") sorted.sort((a, b) => b.unread - a.unread);
    if (sortBy === "name") sorted.sort((a, b) => (a.nickname || a.full_name || "").localeCompare(b.nickname || b.full_name || ""));
    if (sortBy === "weight") sorted.sort((a, b) => (b.latest_weight ?? -Infinity) - (a.latest_weight ?? -Infinity));
    return sorted;
  }, [clients, query, sortBy]);
  if (!isAdmin || !user) return null;
  const totalUnread = clients.reduce((s, c) => s + c.unread, 0);
  return /* @__PURE__ */ jsxRuntimeExports.jsx("main", { className: "bg-soft min-h-[calc(100svh-4rem)]", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "container mx-auto px-3 sm:px-4 py-6 sm:py-10 max-w-5xl", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("header", { className: "relative overflow-hidden rounded-3xl border border-border bg-card p-5 sm:p-7 shadow-[var(--shadow-card)] mb-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { "aria-hidden": true, className: "absolute -right-16 -top-16 h-56 w-56 rounded-full bg-primary/10 blur-3xl" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative flex items-center gap-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-12 w-12 sm:h-14 sm:w-14 rounded-2xl bg-primary text-primary-foreground grid place-items-center shrink-0 shadow-soft", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "h-6 w-6 sm:h-7 sm:w-7" }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0 flex-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs font-medium uppercase tracking-[0.18em] text-primary mb-1", children: "Panou coach" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "font-display text-3xl sm:text-4xl font-bold tracking-tight", children: "Clienții tăi" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-muted-foreground mt-1", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-num font-semibold text-foreground", children: clients.length }),
            " ",
            "clienți",
            totalUnread > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              " · ",
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-destructive font-semibold font-num", children: totalUnread }),
              " ",
              "mesaje necitite"
            ] })
          ] })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Tabs, { defaultValue: "clients", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsList, { className: "w-full grid grid-cols-2 h-auto bg-card p-1.5 rounded-2xl border shadow-[var(--shadow-card)]", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsTrigger, { value: "clients", className: "gap-1.5 text-xs sm:text-sm py-2.5 rounded-xl", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "h-4 w-4" }),
          " Clienți"
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsTrigger, { value: "groups", className: "gap-1.5 text-xs sm:text-sm py-2.5 rounded-xl", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(MessageCircle, { className: "h-4 w-4" }),
          " Grupuri"
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(TabsContent, { value: "clients", className: "mt-5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-3 mb-3 rounded-2xl shadow-[var(--shadow-card)] flex flex-col sm:flex-row gap-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative flex-1", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Search, { className: "h-4 w-4 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: "Caută după nume, poreclă sau email...", value: query, onChange: (e) => setQuery(e.target.value), className: "pl-9" })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-1.5 shrink-0", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs(SortBtn, { active: sortBy === "unread", onClick: () => setSortBy("unread"), children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(Inbox, { className: "h-3.5 w-3.5" }),
              "Necitite"
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(SortBtn, { active: sortBy === "name", onClick: () => setSortBy("name"), children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowUpDown, { className: "h-3.5 w-3.5" }),
              "Nume"
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(SortBtn, { active: sortBy === "weight", onClick: () => setSortBy("weight"), children: "Greutate" })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-2.5", children: [
          !loaded && Array.from({
            length: 4
          }).map((_, i) => /* @__PURE__ */ jsxRuntimeExports.jsx(Card, { className: "p-4 rounded-2xl skeleton h-[72px] border-0" }, i)),
          loaded && filtered.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-10 rounded-2xl text-center", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Inbox, { className: "h-10 w-10 mx-auto text-muted-foreground/40 mb-3" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: query ? "Niciun client nu corespunde căutării." : "Niciun client încă. Vor apărea aici după înregistrare." })
          ] }),
          filtered.map((c) => {
            const display = c.nickname ? `${c.nickname} (${c.full_name || "—"})` : c.full_name || "(fără nume)";
            return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { to: "/admin/$clientId", params: {
              clientId: c.id
            }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-3 sm:p-4 rounded-2xl shadow-[var(--shadow-card)] hover:shadow-soft transition-all hover:-translate-y-0.5 flex items-center justify-between gap-2 cursor-pointer", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs(Avatar, { className: "h-11 w-11 shrink-0 ring-1 ring-border", children: [
                c.avatar_url && /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarImage, { src: c.avatar_url }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(AvatarFallback, { className: "bg-primary/15 text-primary font-display font-bold", children: (c.nickname || c.full_name || "?").slice(0, 2).toUpperCase() })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0 flex-1", children: [
                /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-display font-semibold truncate flex items-center gap-2", children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "truncate", children: display }),
                  c.unread > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1 text-[10px] sm:text-xs bg-destructive text-destructive-foreground rounded-full px-2 py-0.5 shrink-0 font-num", children: [
                    /* @__PURE__ */ jsxRuntimeExports.jsx(MessageCircle, { className: "h-3 w-3" }),
                    " ",
                    c.unread
                  ] })
                ] }),
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs sm:text-sm text-muted-foreground truncate", children: c.email })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 sm:gap-4 text-sm shrink-0", children: [
                /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-right", children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-display font-bold text-primary text-sm sm:text-base font-num", children: c.latest_weight != null ? `${c.latest_weight} kg` : "—" }),
                  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-[10px] sm:text-xs text-muted-foreground", children: [
                    /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-num", children: c.entries }),
                    " înreg."
                  ] })
                ] }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "h-5 w-5 text-muted-foreground" })
              ] })
            ] }) }, c.id);
          })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TabsContent, { value: "groups", className: "mt-5", children: /* @__PURE__ */ jsxRuntimeExports.jsx(GroupsManager, { currentUserId: user.id }) })
    ] })
  ] }) });
}
function SortBtn({
  active,
  onClick,
  children
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "button", variant: active ? "default" : "ghost", size: "sm", onClick, className: "gap-1.5 rounded-full text-xs", children });
}
export {
  AdminHome as component
};
