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