import { jsx as e, jsxs as t } from "react/jsx-runtime";
import { useCallback as i } from "react";
import { useNavigate as B } from "react-router-dom";
import { useTranslation as S } from "react-i18next";
import { Star as u, Globe as M, Building2 as g, User as k, AlertCircle as W, Layers as j } from "lucide-react";
import { h as R, ad as E } from "./index-Dh9kUeDn.js";
import { T as v } from "./TenantCard-D0O2ivhU.js";
function U() {
  const { t: r } = S("navigation"), l = B(), {
    currentTenant: o,
    userTenants: d,
    b2bTenants: m,
    personalTenant: s,
    switchTenant: b,
    setDefaultTenant: y,
    clearDefaultTenant: N,
    isLoading: D,
    hasGlobalRoles: T
  } = R(), { enableB2C: C } = E(), n = !d.some((a) => a.isDefault), p = i(async (a) => {
    try {
      await b(a), l("/myspace");
    } catch (f) {
      console.error("Failed to switch tenant:", f);
    }
  }, [b, l]), h = i(async (a) => {
    try {
      await y(a);
    } catch (f) {
      console.error("Failed to set default tenant:", f);
    }
  }, [y]), P = i(async () => {
    try {
      await N();
    } catch (a) {
      console.error("Failed to clear default tenant:", a);
    }
  }, [N]), w = i((a) => {
    l(`/administration/tenants/${a}`);
  }, [l]);
  if (D)
    return /* @__PURE__ */ e("div", { className: "flex items-center justify-center min-h-[400px]", children: /* @__PURE__ */ e("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-[var(--color-accent-500)]" }) });
  const c = d.find((a) => a.isDefault), x = d.filter((a) => a.type !== "Business" && a.type !== "Personal");
  return /* @__PURE__ */ t("div", { className: "space-y-8", children: [
    /* @__PURE__ */ t("div", { children: [
      /* @__PURE__ */ e("h1", { className: "text-2xl font-bold text-[var(--text-primary)]", children: r("myspace.tenants.title", "My Workspaces") }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] mt-1", children: r("myspace.tenants.description", "Manage your workspace access and set your default workspace") })
    ] }),
    /* @__PURE__ */ t("section", { children: [
      /* @__PURE__ */ t("div", { className: "flex items-center gap-2 mb-4", children: [
        /* @__PURE__ */ e(u, { className: "w-5 h-5 text-amber-500" }),
        /* @__PURE__ */ e("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: r("myspace.tenants.defaultPreference.title", "Default Preference") })
      ] }),
      /* @__PURE__ */ t("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-4 max-w-2xl", children: [
        T && /* @__PURE__ */ e(
          "button",
          {
            onClick: n ? void 0 : P,
            disabled: n,
            className: `relative text-left p-5 bg-[var(--bg-card)] border overflow-hidden transition-all duration-200 ${n ? "border-[var(--color-accent-500)] ring-2 ring-[var(--color-accent-500)]/20" : "border-[var(--border-color)] hover:border-[var(--color-accent-300)] cursor-pointer"}`,
            style: { borderRadius: "var(--radius-card)" },
            children: /* @__PURE__ */ t("div", { className: "flex items-start gap-3", children: [
              /* @__PURE__ */ e("div", { className: "w-12 h-12 rounded-xl flex items-center justify-center bg-gradient-to-br from-emerald-500/20 to-emerald-600/20", children: /* @__PURE__ */ e(M, { className: "w-6 h-6 text-emerald-500" }) }),
              /* @__PURE__ */ t("div", { className: "flex-1 min-w-0", children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
                  /* @__PURE__ */ e("h3", { className: "font-semibold text-[var(--text-primary)]", children: r("myspace.tenants.defaultPreference.global", "Global") }),
                  n && /* @__PURE__ */ t("span", { className: "inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]", children: [
                    /* @__PURE__ */ e(u, { className: "w-3 h-3 fill-current" }),
                    r("tenants.default", "Default")
                  ] })
                ] }),
                /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: r("myspace.tenants.defaultPreference.globalDescription", "No specific workspace on login — choose each time") })
              ] })
            ] })
          }
        ),
        c && /* @__PURE__ */ e(
          "div",
          {
            className: "relative p-5 bg-[var(--bg-card)] border border-[var(--color-accent-500)] ring-2 ring-[var(--color-accent-500)]/20 overflow-hidden",
            style: { borderRadius: "var(--radius-card)" },
            children: /* @__PURE__ */ t("div", { className: "flex items-start gap-3", children: [
              /* @__PURE__ */ e("div", { className: `w-12 h-12 rounded-xl flex items-center justify-center ${c.type === "Business" ? "bg-gradient-to-br from-blue-500/20 to-blue-600/20" : "bg-gradient-to-br from-violet-500/20 to-violet-600/20"}`, children: c.type === "Business" ? /* @__PURE__ */ e(g, { className: "w-6 h-6 text-blue-500" }) : /* @__PURE__ */ e(k, { className: "w-6 h-6 text-violet-500" }) }),
              /* @__PURE__ */ t("div", { className: "flex-1 min-w-0", children: [
                /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
                  /* @__PURE__ */ e("h3", { className: "font-semibold text-[var(--text-primary)] truncate", children: c.name }),
                  /* @__PURE__ */ t("span", { className: "inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]", children: [
                    /* @__PURE__ */ e(u, { className: "w-3 h-3 fill-current" }),
                    r("tenants.default", "Default")
                  ] })
                ] }),
                /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: r("myspace.tenants.defaultPreference.specificDescription", "Auto-connect to this workspace on login") })
              ] })
            ] })
          }
        )
      ] })
    ] }),
    m.length > 0 && /* @__PURE__ */ t("section", { children: [
      /* @__PURE__ */ t("div", { className: "flex items-center gap-2 mb-4", children: [
        /* @__PURE__ */ e(g, { className: "w-5 h-5 text-blue-500" }),
        /* @__PURE__ */ e("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: r("myspace.tenants.b2b.title", "Professional Workspaces") }),
        /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs font-medium rounded-full bg-blue-500/10 text-blue-600", children: "B2B" })
      ] }),
      /* @__PURE__ */ e("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4", children: m.map((a) => /* @__PURE__ */ e(
        v,
        {
          tenant: a,
          isSelected: o?.id === a.id,
          onSetDefault: () => h(a.id),
          onEnter: () => p(a.id),
          onManage: a.isOwner ? () => w(a.id) : void 0
        },
        a.id
      )) })
    ] }),
    C && /* @__PURE__ */ t("section", { children: [
      /* @__PURE__ */ t("div", { className: "flex items-center gap-2 mb-4", children: [
        /* @__PURE__ */ e(k, { className: "w-5 h-5 text-violet-500" }),
        /* @__PURE__ */ e("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: r("myspace.tenants.personal.title", "Personal Workspace") }),
        /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs font-medium rounded-full bg-violet-500/10 text-violet-600", children: "B2C" })
      ] }),
      s ? /* @__PURE__ */ e("div", { className: "max-w-md", children: /* @__PURE__ */ e(
        v,
        {
          tenant: s,
          isSelected: o?.id === s.id,
          onSetDefault: () => h(s.id),
          onEnter: () => p(s.id)
        }
      ) }) : /* @__PURE__ */ t(
        "div",
        {
          className: "flex items-start gap-3 p-4 bg-[var(--warning-bg)] border border-[var(--warning-border)]",
          style: { borderRadius: "var(--radius-card)" },
          children: [
            /* @__PURE__ */ e(W, { className: "w-5 h-5 text-[var(--warning-text)] flex-shrink-0 mt-0.5" }),
            /* @__PURE__ */ t("div", { children: [
              /* @__PURE__ */ e("p", { className: "font-medium text-[var(--warning-text)]", children: r("myspace.tenants.personal.noWorkspace", "No personal workspace") }),
              /* @__PURE__ */ e("p", { className: "text-sm text-[var(--warning-text)] opacity-80 mt-1", children: r(
                "myspace.tenants.personal.noWorkspaceDescription",
                "Your personal workspace will be created automatically when you first access the platform."
              ) })
            ] })
          ]
        }
      )
    ] }),
    x.length > 0 && /* @__PURE__ */ t("section", { children: [
      /* @__PURE__ */ t("div", { className: "flex items-center gap-2 mb-4", children: [
        /* @__PURE__ */ e(j, { className: "w-5 h-5 text-gray-500" }),
        /* @__PURE__ */ e("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: r("myspace.tenants.other.title", "Other Workspaces") })
      ] }),
      /* @__PURE__ */ e("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4", children: x.map((a) => /* @__PURE__ */ e(
        v,
        {
          tenant: a,
          isSelected: o?.id === a.id,
          onSetDefault: () => h(a.id),
          onEnter: () => p(a.id),
          onManage: a.isOwner ? () => w(a.id) : void 0
        },
        a.id
      )) })
    ] }),
    m.length === 0 && !s && x.length === 0 && /* @__PURE__ */ t(
      "div",
      {
        className: "text-center py-12 px-6 bg-[var(--bg-card)] border border-[var(--border-color)]",
        style: { borderRadius: "var(--radius-card)" },
        children: [
          /* @__PURE__ */ e(g, { className: "w-12 h-12 text-[var(--text-tertiary)] mx-auto mb-4" }),
          /* @__PURE__ */ e("h3", { className: "text-lg font-medium text-[var(--text-primary)] mb-2", children: r("myspace.tenants.empty.title", "No workspaces available") }),
          /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] max-w-md mx-auto", children: r(
            "myspace.tenants.empty.description",
            "You don't have access to any workspace yet. Contact your administrator to get access."
          ) })
        ]
      }
    )
  ] });
}
export {
  U as MyTenantsPage,
  U as default
};
//# sourceMappingURL=MyTenantsPage-Cx4IN0vu.js.map
