import { jsx as e, jsxs as s } from "react/jsx-runtime";
import { useState as f, useCallback as S, useMemo as K, useEffect as ee } from "react";
import { useParams as Me, useNavigate as Se } from "react-router-dom";
import { u as Te } from "./useTabNavigation-Bsbskz0i.js";
import { useTranslation as W } from "react-i18next";
import { v as R, x as Ce, a as ke, P as Le, K as Re } from "./index-CeEMms9z.js";
import { U as Be } from "./UnderlinedTabs-BEbz4Kre.js";
import * as Fe from "lucide-react";
import { Loader2 as G, Save as re, GripVertical as Ee, Layers as V, ChevronDown as Pe, ChevronRight as Ue, Edit as qe, Search as Ie, Shield as Q, Eye as Oe, Globe as X, Settings as $e, Users as te, Inbox as ze, AlertCircle as We, Power as ae, PowerOff as se, AlertTriangle as je, CheckCircle as Ge } from "lucide-react";
import { useSensors as Ke, useSensor as ie, PointerSensor as Ve, KeyboardSensor as He, DndContext as _e, closestCenter as Je } from "@dnd-kit/core";
import { sortableKeyboardCoordinates as Qe, SortableContext as Xe, verticalListSortingStrategy as Ye, arrayMove as Ze, useSortable as et } from "@dnd-kit/sortable";
import { CSS as tt } from "@dnd-kit/utilities";
import { u as at, a as st, g as it } from "./tenantIconMap-DKmj47wO.js";
import { u as rt, A as nt } from "./useAccessRequests-BE1aKgyt.js";
function Y(t, n = "w-4 h-4") {
  if (!t) return null;
  if (typeof t == "string") {
    const d = Fe[t];
    return d ? /* @__PURE__ */ e(d, { className: n }) : null;
  }
  return /* @__PURE__ */ e(t, { className: n });
}
function lt() {
  const { t } = W("admin"), [n, r] = f(null), [l, d] = f(!1), [m, c] = f(!1), [o, y] = f(null), [i, u] = f(null), [A, a] = f({
    label: "",
    description: "",
    icon: "",
    route: "",
    displayOrder: 0
  }), w = S(async (g) => {
    if (g) {
      d(!0), y(null);
      try {
        const p = await R.applications.getById(g);
        r(p), a({
          label: p.label,
          description: p.description || "",
          icon: p.icon || "",
          route: p.route || "",
          displayOrder: p.displayOrder
        });
      } catch (p) {
        y(p instanceof Error ? p.message : t("applicationDetail.errors.loadFailed"));
      } finally {
        d(!1);
      }
    }
  }, [t]), F = S(async (g, p) => {
    if (!(!g || !n)) {
      c(!0), y(null), u(null);
      try {
        const x = {
          label: p.label,
          description: p.description || void 0,
          icon: p.icon || void 0,
          route: p.route || void 0,
          displayOrder: p.displayOrder
        };
        await R.applications.update(g, x), u(t("applicationDetail.success.saved")), await w(g);
      } catch (x) {
        y(x instanceof Error ? x.message : t("applicationDetail.errors.saveFailed"));
      } finally {
        c(!1);
      }
    }
  }, [n, t, w]), L = S(async (g) => {
    if (!(!g || !n)) {
      c(!0), y(null), u(null);
      try {
        n.isActive ? await R.applications.deactivate(g) : await R.applications.activate(g), u(
          n.isActive ? t("applicationDetail.success.deactivated") : t("applicationDetail.success.activated")
        ), await w(g);
      } catch (p) {
        y(p instanceof Error ? p.message : t("applicationDetail.errors.toggleFailed"));
      } finally {
        c(!1);
      }
    }
  }, [n, t, w]);
  return {
    application: n,
    loading: l,
    saving: m,
    error: o,
    success: i,
    formData: A,
    setFormData: a,
    setError: y,
    setSuccess: u,
    loadApplication: w,
    handleSaveInfo: F,
    handleToggleStatus: L
  };
}
function ot() {
  const [t, n] = f(/* @__PURE__ */ new Set()), [r, l] = f(/* @__PURE__ */ new Map()), [d, m] = f(/* @__PURE__ */ new Set()), [c, o] = f(!1), [y, i] = f(null), [u, A] = f({
    code: "",
    label: "",
    description: "",
    icon: "",
    route: "",
    displayOrder: 0
  }), [a, w] = f(!1), F = S(async (C, k) => {
    const E = !t.has(k);
    if (n((T) => {
      const M = new Set(T);
      return M.has(k) ? M.delete(k) : M.add(k), M;
    }), E && !r.has(k)) {
      m((T) => new Set(T).add(k));
      try {
        const T = await R.applications.getModuleSections(C, k);
        l((M) => new Map(M).set(k, T));
      } catch (T) {
        console.error("Failed to load sections:", T);
      } finally {
        m((T) => {
          const M = new Set(T);
          return M.delete(k), M;
        });
      }
    }
  }, [t, r]), L = S((C) => {
    A({
      code: "",
      label: "",
      description: "",
      icon: "",
      route: "",
      displayOrder: C || 0
    });
  }, []), g = S(async (C, k, E) => {
    try {
      await R.applications.updateModule(C, k, {
        label: E.label,
        description: E.description || void 0,
        icon: E.icon || void 0,
        route: E.route || void 0,
        displayOrder: E.displayOrder
      }), w(!1), i(null), L();
    } catch (T) {
      throw console.error("Failed to save module:", T), T;
    }
  }, [L]), p = S(async (C, k) => {
    const E = k.map((T, M) => ({ ...T, displayOrder: M }));
    o(!0);
    try {
      await R.applications.reorderModules(C, E.map((T, M) => ({ id: T.id, displayOrder: M })));
    } catch (T) {
      throw console.error("Failed to reorder modules:", T), T;
    } finally {
      o(!1);
    }
  }, []), x = S(async (C, k, E) => {
    const T = E.map((M, P) => ({ ...M, displayOrder: P }));
    l((M) => new Map(M).set(k, T)), o(!0);
    try {
      await R.applications.reorderSections(C, k, T.map((M, P) => ({ id: M.id, displayOrder: P })));
    } catch (M) {
      console.error("Failed to reorder sections:", M);
      try {
        const P = await R.applications.getModuleSections(C, k);
        l((q) => new Map(q).set(k, P));
      } catch (P) {
        console.error("Failed to reload sections:", P);
      }
      throw M;
    } finally {
      o(!1);
    }
  }, []), U = S((C) => {
    i(C), A({
      code: C.code,
      label: C.label,
      description: C.description || "",
      icon: C.icon || "",
      route: C.route || "",
      displayOrder: C.displayOrder
    }), w(!0);
  }, []);
  return {
    expandedModules: t,
    moduleSections: r,
    loadingSections: d,
    reordering: c,
    editingModule: y,
    moduleFormData: u,
    showModuleForm: a,
    toggleModuleExpand: F,
    handleSaveModule: g,
    handleModulesReorder: p,
    handleSectionsReorder: x,
    startEditModule: U,
    resetModuleForm: L,
    setShowModuleForm: w,
    setEditingModule: i,
    setModuleFormData: A
  };
}
const ct = (t, n, r) => {
  const l = n.filter((d) => d.permissionIds.includes(t.id)).map((d) => r.find((m) => m.id === d.id)).filter(Boolean);
  return { permission: t, roles: l };
};
function dt() {
  const [t, n] = f([]), [r, l] = f([]), [d, m] = f([]), c = S(async (i) => {
    try {
      const [u, A] = await Promise.all([
        R.permissions.getMatrix(),
        R.roles.getAll()
      ]), a = `${i.code}.`.toLowerCase(), w = u.permissions.filter(
        (L) => L.path.toLowerCase().startsWith(a)
      );
      l(w), n(A);
      const F = w.map(
        (L) => ct(L, u.roles, A)
      );
      m(F);
    } catch (u) {
      throw console.error("Failed to load permissions data:", u), u;
    }
  }, []), o = S(async () => {
    try {
      const i = await R.roles.getAll();
      n(i);
    } catch (i) {
      throw console.error("Failed to load roles:", i), i;
    }
  }, []), y = K(() => {
    if (d.length === 0) return [];
    const i = /* @__PURE__ */ new Map();
    return d.forEach(({ permission: u, roles: A }) => {
      A.forEach((a) => {
        i.has(a.id) || i.set(a.id, { role: a, permissions: [] }), i.get(a.id).permissions.push(u);
      });
    }), Array.from(i.values()).sort(
      (u, A) => A.permissions.length - u.permissions.length
    );
  }, [d]);
  return {
    roles: t,
    permissions: r,
    permissionsWithRoles: d,
    rolesWithAppAccess: y,
    loadPermissionsData: c,
    loadRolesData: o
  };
}
const pt = (t, n) => {
  if (t.id !== n) return t;
  const r = !t.isAssigned;
  return {
    ...t,
    isAssigned: r,
    sections: t.sections.map((l) => ({ ...l, isAssigned: r }))
  };
}, ut = (t, n, r) => {
  if (t.id !== n) return t;
  const l = t.sections.map(
    (m) => m.id === r ? { ...m, isAssigned: !m.isAssigned } : m
  ), d = l.every((m) => m.isAssigned);
  return {
    ...t,
    isAssigned: d,
    sections: l
  };
}, mt = (t) => ({
  ...t,
  isAssigned: !0,
  sections: t.sections.map((n) => ({ ...n, isAssigned: !0 }))
}), vt = (t) => ({
  ...t,
  isAssigned: !1,
  sections: t.sections.map((n) => ({ ...n, isAssigned: !1 }))
});
function gt() {
  const [t, n] = f([]), [r, l] = f([]), [d, m] = f(!1), [c, o] = f([]), [y, i] = f("FullAccess"), [u, A] = f(""), [a, w] = f(!1), [F, L] = f(null), [g, p] = f("full"), [x, U] = f([]), [C, k] = f(/* @__PURE__ */ new Set()), [E, T] = f(!1), [M, P] = f(!1), [q, N] = f("merge"), [j, H] = f(!1), [le, Z] = f({ modules: 0, sections: 0 }), I = S(async (v) => {
    try {
      const [b, h] = await Promise.all([
        R.applications.getTenants(v),
        R.applications.getAvailableTenants(v)
      ]);
      n(b), l(h.tenants);
    } catch (b) {
      console.error("Failed to load publication data:", b);
    }
  }, []), oe = S(async (v) => {
    T(!0);
    try {
      const b = await R.applications.getModules(v), h = [];
      for (const D of b) {
        const O = (await R.applications.getModuleSections(v, D.id)).map((z) => ({
          id: z.id,
          label: z.label,
          code: z.code,
          icon: z.icon,
          isAssigned: !0
        }));
        h.push({
          id: D.id,
          label: D.label,
          code: D.code,
          icon: D.icon,
          isAssigned: !0,
          sections: O
        });
      }
      U(h);
    } catch (b) {
      console.error("Failed to load bulk modules:", b);
    } finally {
      T(!1);
    }
  }, []), ce = S((v) => {
    k((b) => {
      const h = new Set(b);
      return h.has(v) ? h.delete(v) : h.add(v), h;
    });
  }, []), de = S((v) => {
    U((b) => b.map((h) => pt(h, v)));
  }, []), pe = S((v, b) => {
    U((h) => h.map((D) => ut(D, v, b)));
  }, []), ue = S((v) => {
    const b = v.sections.filter((h) => h.isAssigned).length;
    return b === 0 ? "unchecked" : b === v.sections.length ? "checked" : "indeterminate";
  }, []), me = S(() => {
    const v = x.length, b = x.filter((B) => B.isAssigned || B.sections.some((O) => O.isAssigned)).length, h = x.reduce((B, O) => B + O.sections.length, 0), D = x.reduce((B, O) => B + O.sections.filter((z) => z.isAssigned).length, 0);
    return { totalModules: v, assignedModules: b, totalSections: h, assignedSections: D };
  }, [x]), ve = S(() => {
    U((v) => v.map((b) => mt(b)));
  }, []), ge = S(() => {
    U((v) => v.map((b) => vt(b)));
  }, []), be = S((v) => {
    o(
      (b) => b.includes(v) ? b.filter((h) => h !== v) : [...b, v]
    );
  }, []), he = S(() => {
    if (M) {
      const v = t.filter(
        (b) => b.tenantName.toLowerCase().includes(u.toLowerCase()) || b.tenantSlug.toLowerCase().includes(u.toLowerCase())
      ).map((b) => b.tenantId);
      o(v);
    } else {
      const v = r.filter(
        (b) => b.name.toLowerCase().includes(u.toLowerCase()) || b.slug.toLowerCase().includes(u.toLowerCase())
      ).map((b) => b.id);
      o(v);
    }
  }, [M, t, r, u]), xe = S(() => {
    o([]);
  }, []), _ = S(
    async (v, b) => {
      if (!(!v || c.length === 0))
        try {
          const h = {
            tenantIds: c,
            accessLevel: y,
            accessMode: g,
            mergeMode: q
          };
          g === "custom" && (h.moduleIds = x.filter((D) => D.isAssigned).map((D) => D.id), h.sectionIds = x.flatMap(
            (D) => D.sections.filter((B) => B.isAssigned).map((B) => B.id)
          )), await R.applications.bulkAssignTenants(v, h), m(!1), o([]), i("FullAccess"), p("full"), A(""), P(!1), N("merge"), H(!1), await I(v), b && b();
        } catch (h) {
          throw console.error("Failed to update tenant assignments:", h), h;
        }
    },
    [c, y, g, q, x, I]
  ), fe = S(
    async (v, b) => {
      if (!(!v || c.length === 0))
        try {
          const h = {
            tenantIds: c,
            accessLevel: y,
            accessMode: g
          };
          g === "custom" && (h.moduleIds = x.filter((D) => D.isAssigned).map((D) => D.id), h.sectionIds = x.flatMap(
            (D) => D.sections.filter((B) => B.isAssigned).map((B) => B.id)
          )), await R.applications.bulkAssignTenants(v, h), m(!1), o([]), i("FullAccess"), p("full"), A(""), await I(v), b && b();
        } catch (h) {
          throw console.error("Failed to assign tenants:", h), h;
        }
    },
    [c, y, g, x, I]
  ), ye = S(
    async (v, b) => {
      if (!(!v || c.length === 0)) {
        if (q === "replace" && g === "custom") {
          let h = 0, D = 0;
          for (const B of c)
            try {
              const O = await R.tenants.getModules(B), z = await R.tenants.getSections(B), Ae = new Set(x.filter(($) => $.isAssigned).map(($) => $.id)), De = new Set(x.flatMap(($) => $.sections.filter((J) => J.isAssigned).map((J) => J.id)));
              h += O.filter(($) => !Ae.has($.moduleId)).length, D += z.filter(($) => !De.has($.sectionId)).length;
            } catch {
            }
          if (h > 0 || D > 0) {
            Z({ modules: h, sections: D }), H(!0);
            return;
          }
        }
        await _(v, b);
      }
    },
    [
      c,
      q,
      g,
      x,
      _
    ]
  ), Ne = S(
    async (v, b, h) => {
      if (v)
        try {
          await R.applications.removeFromTenant(v, b), await I(v), h && h();
        } catch (D) {
          throw console.error("Failed to remove tenant:", D), D;
        }
    },
    [I]
  ), we = S(
    async (v, b, h, D) => {
      if (v)
        try {
          await R.applications.updateTenantAccessLevel(v, b, h), await I(v), D && D();
        } catch (B) {
          throw console.error("Failed to update access level:", B), B;
        }
    },
    [I]
  );
  return {
    // State
    assignedTenants: t,
    availableTenants: r,
    showAssignModal: d,
    selectedTenantIds: c,
    selectedAccessLevel: y,
    tenantSearch: u,
    showCustomizeDrawer: a,
    customizingTenant: F,
    bulkAccessMode: g,
    bulkModules: x,
    bulkExpandedModules: C,
    loadingBulkModules: E,
    isUpdateMode: M,
    updateMergeMode: q,
    showConfirmRemovalDialog: j,
    pendingRemovals: le,
    // Setters
    setAssignedTenants: n,
    setAvailableTenants: l,
    setShowAssignModal: m,
    setSelectedTenantIds: o,
    setSelectedAccessLevel: i,
    setTenantSearch: A,
    setShowCustomizeDrawer: w,
    setCustomizingTenant: L,
    setBulkAccessMode: p,
    setBulkModules: U,
    setBulkExpandedModules: k,
    setIsUpdateMode: P,
    setUpdateMergeMode: N,
    setShowConfirmRemovalDialog: H,
    setPendingRemovals: Z,
    // Operations
    loadPublicationData: I,
    loadBulkModules: oe,
    toggleBulkModuleExpand: ce,
    toggleBulkModule: de,
    toggleBulkSection: pe,
    getBulkModuleCheckState: ue,
    getBulkStats: me,
    selectAllBulkModules: ve,
    clearBulkModules: ge,
    toggleTenantSelection: be,
    selectAllFilteredTenants: he,
    clearTenantSelection: xe,
    handleAssignTenants: fe,
    handleUpdateTenants: ye,
    executeUpdateTenants: _,
    handleRemoveTenant: Ne,
    handleUpdateAccessLevel: we
  };
}
function bt({
  formData: t,
  setFormData: n,
  application: r,
  saving: l,
  onSubmit: d
}) {
  const { t: m } = W("admin");
  return /* @__PURE__ */ s("form", { onSubmit: d, className: "space-y-6", children: [
    /* @__PURE__ */ s("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-6", children: [
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: m("applicationDetail.fields.code") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: r.code,
            disabled: !0,
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-tertiary)] border border-[var(--border-color)] text-[var(--text-muted)] cursor-not-allowed"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: m("applicationDetail.fields.label") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: t.label,
            onChange: (c) => n((o) => ({ ...o, label: c.target.value })),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent",
            required: !0
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { className: "md:col-span-2", children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: m("applicationDetail.fields.description") }),
        /* @__PURE__ */ e(
          "textarea",
          {
            value: t.description,
            onChange: (c) => n((o) => ({ ...o, description: c.target.value })),
            rows: 3,
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: m("applicationDetail.fields.icon") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: t.icon,
            onChange: (c) => n((o) => ({ ...o, icon: c.target.value })),
            placeholder: m("applicationDetail.fields.icon"),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: m("applicationDetail.fields.route") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: t.route,
            onChange: (c) => n((o) => ({ ...o, route: c.target.value })),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] }),
      /* @__PURE__ */ s("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-2", children: m("applicationDetail.fields.displayOrder") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "number",
            value: t.displayOrder,
            onChange: (c) => n((o) => ({
              ...o,
              displayOrder: parseInt(c.target.value) || 0
            })),
            className: "w-full px-4 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)] focus:ring-2 focus:ring-[var(--color-accent-600)] focus:border-transparent"
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ s(
      "button",
      {
        type: "submit",
        disabled: l,
        className: "flex items-center gap-2 px-6 py-2 rounded-[var(--radius-button)] font-medium bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] disabled:opacity-50",
        children: [
          l ? /* @__PURE__ */ e(G, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(re, { className: "w-4 h-4" }),
          m("applicationDetail.actions.save")
        ]
      }
    ) })
  ] });
}
function ht({ id: t, disabled: n, children: r }) {
  const {
    attributes: l,
    listeners: d,
    setNodeRef: m,
    transform: c,
    transition: o,
    isDragging: y
  } = et({ id: t, disabled: n }), i = {
    transform: tt.Transform.toString(c),
    transition: o,
    opacity: y ? 0.5 : 1,
    zIndex: y ? 1 : 0
  }, u = n ? null : /* @__PURE__ */ e(
    "button",
    {
      type: "button",
      className: "p-1.5 rounded hover:bg-[var(--bg-hover)] cursor-grab active:cursor-grabbing text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors",
      ...l,
      ...d,
      children: /* @__PURE__ */ e(Ee, { className: "w-4 h-4" })
    }
  );
  return /* @__PURE__ */ e("div", { ref: m, style: i, children: r(u) });
}
function ne({
  items: t,
  onReorder: n,
  renderItem: r,
  disabled: l = !1
}) {
  const [, d] = f(null), m = Ke(
    ie(Ve, {
      activationConstraint: {
        distance: 8
      }
    }),
    ie(He, {
      coordinateGetter: Qe
    })
  );
  return /* @__PURE__ */ e(
    _e,
    {
      sensors: m,
      collisionDetection: Je,
      onDragStart: (o) => d(o.active.id),
      onDragEnd: (o) => {
        const { active: y, over: i } = o;
        if (d(null), i && y.id !== i.id) {
          const u = t.findIndex((w) => w.id === y.id), A = t.findIndex((w) => w.id === i.id), a = Ze(t, u, A);
          n(a);
        }
      },
      children: /* @__PURE__ */ e(
        Xe,
        {
          items: t.map((o) => o.id),
          strategy: Ye,
          disabled: l,
          children: /* @__PURE__ */ e("div", { className: "space-y-2", children: t.map((o) => /* @__PURE__ */ e(ht, { id: o.id, disabled: l, children: (y) => r(o, y) }, o.id)) })
        }
      )
    }
  );
}
const xt = (t, n, r, l, d, m) => n.has(t) ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ e(G, { className: "w-5 h-5 animate-spin text-[var(--text-muted)]" }) }) : r.get(t)?.length === 0 ? /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)] py-2", children: m("applicationDetail.modules.noSections", "No sections") }) : r.get(t) ? /* @__PURE__ */ e(
  ne,
  {
    items: r.get(t).map((c) => ({ ...c, id: c.id })),
    onReorder: (c) => l(t, c),
    disabled: d,
    renderItem: (c, o) => /* @__PURE__ */ s("div", { className: "flex items-center gap-2 p-2 rounded bg-[var(--bg-secondary)] border border-[var(--border-color)]", children: [
      o,
      /* @__PURE__ */ e("div", { className: "p-1 rounded bg-[var(--bg-tertiary)]", children: Y(c.icon, "w-3 h-3") || /* @__PURE__ */ e(V, { className: "w-3 h-3 text-[var(--text-muted)]" }) }),
      /* @__PURE__ */ s("div", { className: "flex-1", children: [
        /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: c.label }),
        /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: c.code })
      ] }),
      /* @__PURE__ */ e(
        "span",
        {
          className: `px-2 py-0.5 text-xs rounded-full ${c.isActive ? "bg-[var(--success-bg)] text-[var(--success-text)]" : "bg-[var(--error-bg)] text-[var(--error-text)]"}`,
          children: c.isActive ? m("common:active") : m("common:inactive")
        }
      )
    ] })
  }
) : null;
function ft({
  application: t,
  expandedModules: n,
  moduleSections: r,
  loadingSections: l,
  reordering: d,
  editingModule: m,
  moduleFormData: c,
  showModuleForm: o,
  saving: y,
  onToggleExpand: i,
  onStartEdit: u,
  onSaveModule: A,
  onCancelEdit: a,
  onModulesReorder: w,
  onSectionsReorder: F,
  setModuleFormData: L
}) {
  const { t: g } = W("admin");
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
      g("applicationDetail.modules.title"),
      " (",
      t.modules.length,
      ")"
    ] }),
    o && m && /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--border-color)]", children: [
      /* @__PURE__ */ e("h4", { className: "text-md font-semibold text-[var(--text-primary)] mb-4", children: g("applicationDetail.modules.edit") }),
      /* @__PURE__ */ s("form", { onSubmit: A, className: "space-y-4", children: [
        /* @__PURE__ */ s("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: g("applicationDetail.fields.code") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: c.code,
                disabled: !0,
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-tertiary)] border border-[var(--border-color)] text-[var(--text-muted)] cursor-not-allowed"
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: g("applicationDetail.fields.label") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: c.label,
                onChange: (p) => L((x) => ({ ...x, label: p.target.value })),
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]",
                required: !0
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: g("applicationDetail.fields.icon") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: c.icon,
                onChange: (p) => L((x) => ({ ...x, icon: p.target.value })),
                placeholder: "Users",
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]"
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: g("applicationDetail.fields.route") }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: c.route,
                onChange: (p) => L((x) => ({ ...x, route: p.target.value })),
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]"
              }
            )
          ] }),
          /* @__PURE__ */ s("div", { className: "md:col-span-2", children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: g("applicationDetail.fields.description") }),
            /* @__PURE__ */ e(
              "textarea",
              {
                value: c.description,
                onChange: (p) => L((x) => ({ ...x, description: p.target.value })),
                rows: 2,
                className: "w-full px-3 py-2 rounded-[var(--radius-input)] bg-[var(--bg-primary)] border border-[var(--border-color)] text-[var(--text-primary)]"
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ s("div", { className: "flex justify-end gap-2", children: [
          /* @__PURE__ */ e(
            "button",
            {
              type: "button",
              onClick: a,
              className: "px-4 py-2 rounded-[var(--radius-button)] font-medium text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]",
              children: g("common:cancel")
            }
          ),
          /* @__PURE__ */ s(
            "button",
            {
              type: "submit",
              disabled: y,
              className: "flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] font-medium bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] disabled:opacity-50",
              children: [
                y ? /* @__PURE__ */ e(G, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(re, { className: "w-4 h-4" }),
                g("common:save")
              ]
            }
          )
        ] })
      ] })
    ] }),
    t.modules.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: g("applicationDetail.modules.empty") }) : /* @__PURE__ */ e(
      ne,
      {
        items: t.modules.map((p) => ({ ...p, id: p.id })),
        onReorder: w,
        disabled: d,
        renderItem: (p, x) => /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--item-color-border)] hover:border-[var(--color-accent-600)] transition-colors", children: [
          /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
            /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
              x,
              /* @__PURE__ */ e("div", { className: "p-2 rounded-[var(--radius-button)] bg-[var(--bg-tertiary)]", children: Y(p.icon, "w-4 h-4") || /* @__PURE__ */ e(V, { className: "w-4 h-4 text-[var(--text-muted)]" }) }),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => i(p.id),
                  className: "p-1 rounded hover:bg-[var(--bg-hover)]",
                  "aria-expanded": n.has(p.id),
                  "aria-label": g("applicationDetail.modules.toggleExpand", "Toggle sections"),
                  children: n.has(p.id) ? /* @__PURE__ */ e(Pe, { className: "w-4 h-4 text-[var(--text-muted)]" }) : /* @__PURE__ */ e(Ue, { className: "w-4 h-4 text-[var(--text-muted)]" })
                }
              ),
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: p.label }),
                /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: p.code })
              ] }),
              /* @__PURE__ */ e(
                "span",
                {
                  className: `ml-2 px-2 py-0.5 text-xs font-medium rounded-full ${p.isActive ? "bg-[var(--success-bg)] text-[var(--success-text)]" : "bg-[var(--error-bg)] text-[var(--error-text)]"}`,
                  children: p.isActive ? g("common:active") : g("common:inactive")
                }
              )
            ] }),
            /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ s("span", { className: "text-sm text-[var(--text-muted)]", children: [
                p.sectionsCount,
                " ",
                g("applicationDetail.modules.sections", "sections")
              ] }),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => u(p),
                  className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] text-[var(--text-secondary)]",
                  "aria-label": g("applicationDetail.modules.edit"),
                  children: /* @__PURE__ */ e(qe, { className: "w-4 h-4" })
                }
              )
            ] })
          ] }),
          n.has(p.id) && /* @__PURE__ */ s("div", { className: "mt-3 pl-10 pt-3 border-t border-[var(--border-color)]", children: [
            /* @__PURE__ */ s("div", { className: "grid grid-cols-2 gap-4 text-sm mb-4", children: [
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ s("span", { className: "text-[var(--text-muted)]", children: [
                  g("applicationDetail.fields.description"),
                  ":"
                ] }),
                /* @__PURE__ */ e("p", { className: "text-[var(--text-primary)]", children: p.description || "-" })
              ] }),
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ s("span", { className: "text-[var(--text-muted)]", children: [
                  g("applicationDetail.fields.route"),
                  ":"
                ] }),
                /* @__PURE__ */ e("p", { className: "text-[var(--text-primary)] font-mono", children: p.route || "-" })
              ] })
            ] }),
            /* @__PURE__ */ s("div", { className: "mt-4", children: [
              /* @__PURE__ */ s("h5", { className: "text-sm font-medium text-[var(--text-secondary)] mb-2", children: [
                g("applicationDetail.modules.sections", "Sections"),
                " (",
                p.sectionsCount,
                ")"
              ] }),
              xt(p.id, l, r, F, d, g)
            ] })
          ] })
        ] })
      }
    )
  ] });
}
function yt({
  application: t,
  permissions: n,
  permissionsWithRoles: r
}) {
  const { t: l } = W("admin"), [d, m] = f(""), [c, o] = f("all"), y = K(() => {
    const a = d.trim().toLowerCase(), w = c.toLowerCase();
    return r.filter(({ permission: F }) => {
      if (c !== "all" && (F.path.toLowerCase().split(".")[1] ?? "") !== w)
        return !1;
      if (a) {
        const L = F.path.toLowerCase(), g = (F.action ?? "").toLowerCase();
        if (!L.includes(a) && !g.includes(a)) return !1;
      }
      return !0;
    });
  }, [r, d, c]), i = d.trim() !== "" || c !== "all", u = n.length, A = y.length;
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
      l("applicationDetail.permissions.title"),
      " (",
      i ? `${A} / ${u}` : u,
      ")"
    ] }),
    /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: l("applicationDetail.permissions.description", {
      path: `${t.code}.*`
    }) }),
    n.length > 0 && /* @__PURE__ */ s("div", { className: "flex flex-col md:flex-row gap-3", children: [
      /* @__PURE__ */ s("div", { className: "flex-1 relative", children: [
        /* @__PURE__ */ e(Ie, { className: "absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-[var(--text-muted)]" }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "text",
            value: d,
            onChange: (a) => m(a.target.value),
            placeholder: l("applicationDetail.permissions.searchPlaceholder"),
            className: "block w-full pl-10 pr-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-input)] bg-[var(--bg-primary)] text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)] text-sm"
          }
        )
      ] }),
      /* @__PURE__ */ s(
        "select",
        {
          value: c,
          onChange: (a) => o(a.target.value),
          className: "md:w-64 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-input)] bg-[var(--bg-primary)] text-[var(--text-primary)] text-sm focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]",
          children: [
            /* @__PURE__ */ e("option", { value: "all", children: l("applicationDetail.permissions.allModules") }),
            t.modules.map((a) => /* @__PURE__ */ e("option", { value: a.code, children: a.label }, a.id))
          ]
        }
      )
    ] }),
    n.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: l("applicationDetail.permissions.empty") }) : y.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: l("applicationDetail.permissions.noResults") }) : /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ s("table", { className: "w-full", children: [
      /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ s("tr", { className: "border-b border-[var(--border-color)]", children: [
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: l("applicationDetail.permissions.path") }),
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: l("applicationDetail.permissions.action") }),
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: l("applicationDetail.permissions.type") }),
        /* @__PURE__ */ e("th", { className: "text-left py-3 px-4 text-sm font-medium text-[var(--text-secondary)]", children: l("applicationDetail.permissions.roles") })
      ] }) }),
      /* @__PURE__ */ e("tbody", { children: y.map(({ permission: a, roles: w }) => /* @__PURE__ */ s(
        "tr",
        {
          className: "border-b border-[var(--border-color)] hover:bg-[var(--bg-hover)]",
          children: [
            /* @__PURE__ */ e("td", { className: "py-3 px-4 font-mono text-sm text-[var(--text-primary)]", children: a.path }),
            /* @__PURE__ */ e("td", { className: "py-3 px-4", children: a.action ? /* @__PURE__ */ e("span", { className: "px-2 py-1 text-xs font-medium rounded-full bg-[var(--accent-bg)] text-[var(--accent-text)]", children: a.action }) : "-" }),
            /* @__PURE__ */ e("td", { className: "py-3 px-4", children: a.isWildcard ? /* @__PURE__ */ e("span", { className: "px-2 py-1 text-xs font-medium rounded-full bg-[var(--warning-bg)] text-[var(--warning-text)]", children: l("applicationDetail.permissions.wildcard", "Wildcard") }) : /* @__PURE__ */ e("span", { className: "px-2 py-1 text-xs font-medium rounded-full bg-[var(--bg-tertiary)] text-[var(--text-muted)]", children: l("applicationDetail.permissions.specific", "Specific") }) }),
            /* @__PURE__ */ e("td", { className: "py-3 px-4", children: /* @__PURE__ */ s("div", { className: "flex flex-wrap gap-1", children: [
              w.length === 0 ? /* @__PURE__ */ e("span", { className: "text-[var(--text-muted)] text-sm", children: "-" }) : w.slice(0, 3).map((F) => /* @__PURE__ */ e(
                "span",
                {
                  className: "px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--color-accent-100)] text-[var(--color-accent-700)]",
                  children: F.name
                },
                F.id
              )),
              w.length > 3 && /* @__PURE__ */ s("span", { className: "px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--bg-tertiary)] text-[var(--text-muted)]", children: [
                "+",
                w.length - 3
              ] })
            ] }) })
          ]
        },
        a.id
      )) })
    ] }) })
  ] });
}
function Nt({
  rolesWithAppAccess: t,
  onNavigateToRole: n
}) {
  const { t: r } = W("admin");
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
      r("applicationDetail.roles.title"),
      " (",
      t.length,
      ")"
    ] }),
    /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: r("applicationDetail.roles.description") }),
    t.length === 0 ? /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-muted)]", children: r("applicationDetail.roles.empty") }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: t.map(({ role: l, permissions: d }) => /* @__PURE__ */ s(
      "div",
      {
        className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--item-color-border)] hover:border-[var(--color-accent-600)] transition-colors",
        children: [
          /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
            /* @__PURE__ */ s("div", { className: "flex items-center gap-3", children: [
              /* @__PURE__ */ e("div", { className: "p-2 rounded-[var(--radius-button)] bg-[var(--color-accent-100)]", children: /* @__PURE__ */ e(Q, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
              /* @__PURE__ */ s("div", { children: [
                /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
                  /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: l.name }),
                  l.isSystem && /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs font-medium rounded-full bg-[var(--warning-bg)] text-[var(--warning-text)]", children: r("applicationDetail.roles.system", "System") })
                ] }),
                /* @__PURE__ */ s("p", { className: "text-sm text-[var(--text-muted)]", children: [
                  l.usersCount,
                  " ",
                  r("applicationDetail.roles.users"),
                  " • ",
                  d.length,
                  " ",
                  r("applicationDetail.roles.permissions")
                ] })
              ] })
            ] }),
            /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ s(
              "button",
              {
                onClick: () => n(l.id),
                className: "flex items-center gap-1 px-3 py-1.5 rounded-[var(--radius-button)] text-sm font-medium text-[var(--color-accent-600)] hover:bg-[var(--color-accent-100)]",
                children: [
                  /* @__PURE__ */ e(Oe, { className: "w-4 h-4" }),
                  r("applicationDetail.roles.viewRole")
                ]
              }
            ) })
          ] }),
          /* @__PURE__ */ s("div", { className: "mt-3 flex flex-wrap gap-1", children: [
            d.slice(0, 5).map((m) => /* @__PURE__ */ s(
              "span",
              {
                className: "px-2 py-0.5 text-xs font-mono rounded bg-[var(--bg-tertiary)] text-[var(--text-muted)]",
                children: [
                  m.path.split(".").pop(),
                  m.isWildcard && ".*"
                ]
              },
              m.id
            )),
            d.length > 5 && /* @__PURE__ */ s("span", { className: "px-2 py-0.5 text-xs rounded bg-[var(--bg-tertiary)] text-[var(--text-muted)]", children: [
              "+",
              d.length - 5,
              " ",
              r("applicationDetail.roles.more", "more")
            ] })
          ] })
        ]
      },
      l.id
    )) })
  ] });
}
const wt = (t) => {
  switch (t) {
    case "FullAccess":
      return "bg-green-500";
    case "RequestAccess":
      return "bg-amber-500";
    case "Disabled":
      return "bg-gray-400";
    default:
      return "bg-gray-400";
  }
}, At = (t) => {
  switch (t) {
    case "FullAccess":
      return "fullAccess";
    case "RequestAccess":
      return "requestAccess";
    case "Disabled":
      return "disabled";
    default:
      return "disabled";
  }
}, Dt = () => {
  const { getIconForType: t } = at();
  return (n) => {
    const r = t(n), l = st(r.icon), d = it(r.color);
    return { Icon: l, bgClass: d.bg, colorClass: d.text };
  };
}, Mt = ({
  assignedTenants: t
}) => {
  const { t: n } = W("admin"), r = Dt();
  return /* @__PURE__ */ s("div", { className: "space-y-4", children: [
    /* @__PURE__ */ s("div", { children: [
      /* @__PURE__ */ s("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
        n("applicationDetail.publication.title", "Tenant Publication"),
        " (",
        t.length,
        ")"
      ] }),
      /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-muted)]", children: n("applicationDetail.publication.description", "Manage which tenants have access to this application") })
    ] }),
    /* @__PURE__ */ s("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-3 p-4 rounded-[var(--radius-card)] bg-[var(--bg-tertiary)] border border-[var(--border-color)]", children: [
      /* @__PURE__ */ s("div", { className: "flex items-start gap-2", children: [
        /* @__PURE__ */ e("div", { className: "w-3 h-3 mt-1 rounded-full bg-green-500 flex-shrink-0" }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: n("applicationDetail.publication.accessLevels.fullAccess", "Full Access") }),
          /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: n("applicationDetail.publication.accessLevels.fullAccessDesc", "Users can use all features") })
        ] })
      ] }),
      /* @__PURE__ */ s("div", { className: "flex items-start gap-2", children: [
        /* @__PURE__ */ e("div", { className: "w-3 h-3 mt-1 rounded-full bg-amber-500 flex-shrink-0" }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: n("applicationDetail.publication.accessLevels.requestAccess", "Request Access") }),
          /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: n("applicationDetail.publication.accessLevels.requestAccessDesc", "Requires access request") })
        ] })
      ] }),
      /* @__PURE__ */ s("div", { className: "flex items-start gap-2", children: [
        /* @__PURE__ */ e("div", { className: "w-3 h-3 mt-1 rounded-full bg-gray-400 flex-shrink-0" }),
        /* @__PURE__ */ s("div", { children: [
          /* @__PURE__ */ e("p", { className: "text-sm font-medium text-[var(--text-primary)]", children: n("applicationDetail.publication.accessLevels.disabled", "Disabled") }),
          /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-muted)]", children: n("applicationDetail.publication.accessLevels.disabledDesc", "Not visible for tenant") })
        ] })
      ] })
    ] }),
    t.length === 0 ? /* @__PURE__ */ s("div", { className: "text-center py-12", children: [
      /* @__PURE__ */ e(X, { className: "w-12 h-12 mx-auto text-[var(--text-muted)] mb-4" }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-muted)]", children: n("applicationDetail.publication.empty", "No tenants have access to this application yet") })
    ] }) : /* @__PURE__ */ e("div", { className: "space-y-3", children: t.map((l) => {
      const { Icon: d, bgClass: m, colorClass: c } = r(l.tenantType), o = l.tenantStatus === "Active" ? "bg-[var(--success-bg)] text-[var(--success-text)]" : "bg-[var(--warning-bg)] text-[var(--warning-text)]";
      return /* @__PURE__ */ s(
        "div",
        {
          className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--item-color-border)] hover:border-[var(--color-accent-600)] transition-colors",
          children: [
            /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: [
              /* @__PURE__ */ s("div", { className: "flex items-center gap-3", children: [
                /* @__PURE__ */ e("div", { className: `p-2 rounded-[var(--radius-button)] ${m}`, children: /* @__PURE__ */ e(d, { className: `w-5 h-5 ${c}` }) }),
                /* @__PURE__ */ s("div", { children: [
                  /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
                    /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: l.tenantName }),
                    /* @__PURE__ */ e("span", { className: `px-2 py-0.5 text-xs font-medium rounded-full ${o}`, children: l.tenantStatus })
                  ] }),
                  /* @__PURE__ */ s("p", { className: "text-sm text-[var(--text-muted)]", children: [
                    l.tenantSlug,
                    " • ",
                    l.tenantType
                  ] })
                ] })
              ] }),
              /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
                /* @__PURE__ */ e("div", { className: `w-2.5 h-2.5 rounded-full ${wt(l.accessLevel)}` }),
                /* @__PURE__ */ e("span", { className: "px-3 py-1.5 rounded-[var(--radius-input)] bg-[var(--bg-secondary)] border border-[var(--border-color)] text-sm text-[var(--text-primary)]", children: n(`applicationDetail.publication.accessLevels.${At(l.accessLevel)}`, l.accessLevel) })
              ] })
            ] }),
            /* @__PURE__ */ s("div", { className: "mt-2 text-xs text-[var(--text-muted)]", children: [
              n("applicationDetail.publication.assignedAt", "Assigned"),
              ": ",
              new Date(l.assignedAt).toLocaleDateString(),
              l.assignedBy && ` ${n("applicationDetail.publication.by", "by")} ${l.assignedBy}`
            ] })
          ]
        },
        l.tenantId
      );
    }) })
  ] });
}, St = ["info", "modules", "permissions", "roles", "publication", "requests"];
function $t() {
  const { id: t } = Me(), n = Se(), { t: r } = W("admin"), { hasPermission: l } = Ce(), { currentTenant: d, isGlobalView: m } = ke(), c = l("administration.applications.execute"), { activeTab: o, setActiveTab: y } = Te("info", St), i = lt(), u = ot(), A = dt(), a = gt(), w = rt("application", t), { loadApplication: F } = i, { loadPermissionsData: L } = A, { loadPublicationData: g } = a, { loadRequests: p } = w, x = i.application, U = A.permissions.length, C = a.assignedTenants.length, k = K(() => m || !d ? a.availableTenants : a.availableTenants.filter((N) => N.slug === d.slug), [a.availableTenants, m, d]), E = K(() => m || !d ? a.assignedTenants : a.assignedTenants.filter((N) => N.tenantSlug === d.slug), [a.assignedTenants, m, d]);
  ee(() => {
    t && F(t);
  }, [t, F]), ee(() => {
    x && ((o === "permissions" || o === "roles") && U === 0 && L(x), o === "publication" && C === 0 && g(t), o === "requests" && p());
  }, [
    o,
    t,
    x,
    U,
    C,
    L,
    g,
    p
  ]);
  const T = [
    { id: "info", label: r("applicationDetail.tabs.info"), icon: $e },
    { id: "modules", label: r("applicationDetail.tabs.modules"), icon: V },
    { id: "permissions", label: r("applicationDetail.tabs.permissions"), icon: Q },
    { id: "roles", label: r("applicationDetail.tabs.roles"), icon: te },
    { id: "publication", label: r("applicationDetail.tabs.publication"), icon: X },
    { id: "requests", label: r("applicationDetail.tabs.requests"), icon: ze }
  ];
  if (i.loading)
    return /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-64", children: /* @__PURE__ */ e(G, { className: "w-8 h-8 animate-spin text-[var(--color-accent-500)]" }) });
  if (i.error || !i.application)
    return /* @__PURE__ */ s("div", { className: "text-center py-12", children: [
      /* @__PURE__ */ e(We, { className: "w-12 h-12 text-[var(--error-text)] mx-auto mb-4" }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)]", children: i.error || r("applicationDetail.notFound") }),
      /* @__PURE__ */ e(
        "button",
        {
          onClick: () => n("/administration/applications"),
          className: "mt-4 px-4 py-2 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)]",
          children: r("applicationDetail.backToList")
        }
      )
    ] });
  const M = A.permissions.length > 0 || o === "permissions" || o === "roles", P = a.assignedTenants.length > 0 || o === "publication", q = [
    {
      label: r("applicationDetail.stats.modules"),
      value: i.application.modules?.length || 0,
      icon: /* @__PURE__ */ e(V, { className: "w-5 h-5" }),
      accent: 0
    },
    {
      label: r("applicationDetail.stats.permissions"),
      value: M ? A.permissions.length : "—",
      icon: /* @__PURE__ */ e(Q, { className: "w-5 h-5" }),
      accent: 1
    },
    {
      label: r("applicationDetail.stats.rolesWithAccess"),
      value: M ? A.rolesWithAppAccess.length : "—",
      icon: /* @__PURE__ */ e(te, { className: "w-5 h-5" }),
      accent: 2
    },
    {
      label: r("applicationDetail.stats.assignedTenants"),
      value: P ? E.length : "—",
      icon: /* @__PURE__ */ e(X, { className: "w-5 h-5" }),
      accent: 3
    },
    {
      label: r("applicationDetail.stats.status"),
      // Active/inactive status is conveyed by the value text + icon + the header badge —
      // the KpiCard stays neutral (status colour belongs to the badge, not a KPI tile).
      value: i.application.isActive ? r("common:active") : r("common:inactive"),
      icon: i.application.isActive ? /* @__PURE__ */ e(ae, { className: "w-5 h-5" }) : /* @__PURE__ */ e(se, { className: "w-5 h-5" }),
      accent: "neutral"
    }
  ];
  return /* @__PURE__ */ e(
    Le,
    {
      title: i.application.label,
      subtitle: i.application.description,
      icon: Y(i.application.icon, "w-6 h-6"),
      breadcrumbs: [
        { label: r("breadcrumb.admin", { ns: "navigation" }), href: "/administration" },
        { label: r("applications.title"), href: "/administration/applications" },
        { label: i.application.label || "" }
      ],
      actions: /* @__PURE__ */ s("div", { className: "flex items-center gap-2 ml-auto", children: [
        /* @__PURE__ */ e(
          "span",
          {
            className: `px-3 py-1 rounded-[var(--radius-badge)] text-sm font-medium ${i.application.isActive ? "bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)]" : "bg-[var(--bg-tertiary)] text-[var(--text-secondary)] border border-[var(--border-color)]"}`,
            children: i.application.isActive ? r("common:active") : r("common:inactive")
          }
        ),
        c && /* @__PURE__ */ s(
          "button",
          {
            onClick: () => i.handleToggleStatus(t),
            disabled: i.saving,
            className: `inline-flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] font-medium transition-colors ${i.application.isActive ? "bg-[var(--error-bg)] text-[var(--error-text)] border border-[var(--error-border)] hover:bg-[var(--error-border)]" : "bg-[var(--success-bg)] text-[var(--success-text)] border border-[var(--success-border)] hover:bg-[var(--success-border)]"} disabled:opacity-50`,
            children: [
              i.saving && /* @__PURE__ */ e(G, { className: "w-4 h-4 animate-spin" }),
              !i.saving && i.application.isActive && /* @__PURE__ */ e(se, { className: "w-4 h-4" }),
              !i.saving && !i.application.isActive && /* @__PURE__ */ e(ae, { className: "w-4 h-4" }),
              i.application.isActive ? r("applicationDetail.deactivate") : r("applicationDetail.activate")
            ]
          }
        )
      ] }),
      children: /* @__PURE__ */ s("div", { className: "space-y-6", children: [
        i.error && /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--error-bg)] border border-[var(--error-border)] text-[var(--error-text)] flex items-center gap-2", children: [
          /* @__PURE__ */ e(je, { className: "w-5 h-5 flex-shrink-0" }),
          i.error
        ] }),
        i.success && /* @__PURE__ */ s("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--success-bg)] border border-[var(--success-border)] text-[var(--success-text)] flex items-center gap-2", children: [
          /* @__PURE__ */ e(Ge, { className: "w-5 h-5 flex-shrink-0" }),
          i.success
        ] }),
        /* @__PURE__ */ e("div", { className: "grid grid-cols-1 md:grid-cols-3 lg:grid-cols-5 gap-4", children: q.map((N) => /* @__PURE__ */ e(
          Re,
          {
            title: N.label,
            value: N.value,
            icon: N.icon,
            accent: N.accent
          },
          N.label
        )) }),
        /* @__PURE__ */ e(
          Be,
          {
            tabs: T.map((N) => ({
              id: N.id,
              label: N.label,
              icon: /* @__PURE__ */ e(N.icon, { className: "w-4 h-4" })
            })),
            activeTab: o,
            onTabChange: y,
            ariaLabel: r("applicationDetail.tabs.label", "Application tabs")
          }
        ),
        /* @__PURE__ */ s(
          "div",
          {
            role: "tabpanel",
            id: `tabpanel-${o}`,
            "aria-labelledby": `tab-${o}`,
            children: [
              o === "info" && /* @__PURE__ */ e(
                bt,
                {
                  formData: i.formData,
                  setFormData: i.setFormData,
                  application: i.application,
                  saving: i.saving,
                  onSubmit: () => i.handleSaveInfo(t, i.formData)
                }
              ),
              o === "modules" && /* @__PURE__ */ e(
                ft,
                {
                  application: i.application,
                  expandedModules: u.expandedModules,
                  moduleSections: u.moduleSections,
                  loadingSections: u.loadingSections,
                  reordering: u.reordering,
                  editingModule: u.editingModule,
                  moduleFormData: u.moduleFormData,
                  showModuleForm: u.showModuleForm,
                  saving: i.saving,
                  onToggleExpand: (N) => u.toggleModuleExpand(t, N),
                  onStartEdit: u.startEditModule,
                  onSaveModule: async () => {
                    await u.handleSaveModule(
                      t,
                      u.editingModule.id,
                      u.moduleFormData
                    ), i.setSuccess(r("applicationDetail.success.moduleUpdated")), await i.loadApplication(t);
                  },
                  onCancelEdit: () => {
                    u.setShowModuleForm(!1), u.setEditingModule(null);
                  },
                  onModulesReorder: async (N) => {
                    await u.handleModulesReorder(t, N), await i.loadApplication(t);
                  },
                  onSectionsReorder: (N, j) => u.handleSectionsReorder(t, N, j),
                  setModuleFormData: (N) => u.setModuleFormData(typeof N == "function" ? N(u.moduleFormData) : N)
                }
              ),
              o === "permissions" && /* @__PURE__ */ e(
                yt,
                {
                  application: i.application,
                  permissions: A.permissions,
                  permissionsWithRoles: A.permissionsWithRoles
                }
              ),
              o === "roles" && /* @__PURE__ */ e(
                Nt,
                {
                  rolesWithAppAccess: A.rolesWithAppAccess,
                  onNavigateToRole: (N) => n(`/administration/permissions/roles/${N}`)
                }
              ),
              o === "publication" && /* @__PURE__ */ e(
                Mt,
                {
                  application: i.application,
                  assignedTenants: E,
                  availableTenants: k,
                  showAssignModal: a.showAssignModal,
                  selectedTenantIds: a.selectedTenantIds,
                  selectedAccessLevel: a.selectedAccessLevel,
                  tenantSearch: a.tenantSearch,
                  showCustomizeDrawer: a.showCustomizeDrawer,
                  customizingTenant: a.customizingTenant,
                  bulkAccessMode: a.bulkAccessMode,
                  bulkModules: a.bulkModules,
                  bulkExpandedModules: a.bulkExpandedModules,
                  loadingBulkModules: a.loadingBulkModules,
                  isUpdateMode: a.isUpdateMode,
                  updateMergeMode: a.updateMergeMode,
                  showConfirmRemovalDialog: a.showConfirmRemovalDialog,
                  pendingRemovals: a.pendingRemovals,
                  saving: i.saving,
                  onAddTenant: () => {
                    a.loadPublicationData(t), a.setShowAssignModal(!0);
                  },
                  onRemoveTenant: (N) => a.handleRemoveTenant(t, N, () => {
                    i.setSuccess(r("applicationDetail.publication.success.removed"));
                  }),
                  onUpdateAccessLevel: (N, j) => a.handleUpdateAccessLevel(t, N, j, () => {
                    i.setSuccess(r("applicationDetail.publication.success.updated"));
                  }),
                  onCustomizeTenant: (N) => {
                    a.setCustomizingTenant(N), a.setShowCustomizeDrawer(!0);
                  },
                  onCloseCustomizeDrawer: () => {
                    a.setShowCustomizeDrawer(!1), a.setCustomizingTenant(null), a.loadPublicationData(t);
                  },
                  onAssignTenants: () => a.handleAssignTenants(t, () => {
                    i.setSuccess(r("applicationDetail.publication.success.assigned")), a.loadPublicationData(t);
                  }),
                  onUpdateTenants: () => a.handleUpdateTenants(t, () => {
                    i.setSuccess(r("applicationDetail.publication.success.updated")), a.loadPublicationData(t);
                  }),
                  onExecuteUpdateTenants: () => a.executeUpdateTenants(t, () => {
                    i.setSuccess(r("applicationDetail.publication.success.updated")), a.loadPublicationData(t);
                  }),
                  onCancelRemovalDialog: () => {
                    a.setShowConfirmRemovalDialog(!1), a.setUpdateMergeMode("merge");
                  },
                  setShowAssignModal: a.setShowAssignModal,
                  setSelectedTenantIds: a.setSelectedTenantIds,
                  setSelectedAccessLevel: a.setSelectedAccessLevel,
                  setTenantSearch: a.setTenantSearch,
                  setBulkAccessMode: a.setBulkAccessMode,
                  setIsUpdateMode: a.setIsUpdateMode,
                  setUpdateMergeMode: a.setUpdateMergeMode,
                  onToggleTenantSelection: a.toggleTenantSelection,
                  onSelectAllFilteredTenants: a.selectAllFilteredTenants,
                  onClearTenantSelection: a.clearTenantSelection,
                  onLoadBulkModules: () => a.loadBulkModules(t),
                  onToggleBulkModuleExpand: a.toggleBulkModuleExpand,
                  onToggleBulkModule: a.toggleBulkModule,
                  onToggleBulkSection: a.toggleBulkSection,
                  onGetBulkModuleCheckState: a.getBulkModuleCheckState,
                  onGetBulkStats: a.getBulkStats,
                  onSelectAllBulkModules: a.selectAllBulkModules,
                  onClearBulkModules: a.clearBulkModules,
                  appId: t
                }
              ),
              o === "requests" && /* @__PURE__ */ e(
                nt,
                {
                  requests: w.requests,
                  loading: w.loading,
                  onReload: () => w.loadRequests()
                }
              )
            ]
          }
        )
      ] })
    }
  );
}
export {
  $t as default
};
//# sourceMappingURL=ApplicationDetailPage-BQnEyH23.js.map
