import { SideBarItem } from "./SidebarItem"; import { TFunction, type i18n as I18n } from "i18next"; import { AppConfiguration } from "~/utils/db/appConfiguration.db.server"; import IconSettings from "~/components/layouts/icons/IconSettings"; import IconDashboard from "~/components/layouts/icons/IconDashboard"; import IconAdmin from "~/components/layouts/icons/IconAdmin"; import IconNotifications from "~/components/layouts/icons/IconNotifications"; import IconEmails from "~/components/layouts/icons/IconEmails"; import IconKeys from "~/components/layouts/icons/IconKeys"; import IconWorkflows from "~/components/layouts/icons/IconWorkflows"; import AddressBookIcon from "~/components/ui/icons/crm/AddressBookIcon"; import IconDocs from "~/components/layouts/icons/IconDocs"; import ViewListIcon from "~/components/ui/icons/ViewListIcon"; import CalendarIcon from "~/components/ui/icons/CalendarIcon"; import { UI_NAV_IDS } from "~/application/ui/uiRegistry"; import { appPath } from "~/utils/app/CanonicalUrlUtils"; import { absoluteAdminPath, type PublicDomainRoutingConfig } from "~/utils/app/CrossHostUrls"; import { resolveConnectorNavState } from "~/utils/connector/connectorNavState"; import { WALKING_SKELETON_MODULE_KEY } from "~/modules/walkingSkeleton/constants"; import { SearchIcon } from "~/components/ui/icons/vendor"; type Props = { t: TFunction; i18n: I18n; tenantId: string; appConfiguration: AppConfiguration | null; routing?: PublicDomainRoutingConfig; productAccess?: Record; }; export const AppSidebar = ({ t, tenantId, routing, productAccess }: Props): SideBarItem[] => { const tenantPath = (path?: string) => appPath({ tenantSlug: tenantId, path, mode: "host-aware" }); const hasFeatureAccess = (featureKey: string) => productAccess?.[featureKey]?.allowed === true; const hasDashboardAccess = productAccess ? hasFeatureAccess("dashboard") : true; // R-P1c Konnektor-Demo: Walking-Skeleton-Eintrag zeigt die drei Gate-Zustaende (aktiv/gesperrt/ausgeblendet). const walkingSkeletonDecision = productAccess?.[WALKING_SKELETON_MODULE_KEY]; const walkingSkeletonState = walkingSkeletonDecision ? resolveConnectorNavState(walkingSkeletonDecision) : "hidden"; const productCoreItems: SideBarItem[] = [ ...(hasFeatureAccess("search") ? [ { id: UI_NAV_IDS.appSearch, title: t("search.nav.title"), path: tenantPath("search"), icon: , permission: "search.use" as const, }, ] : []), ...(hasFeatureAccess("automation") ? [ { id: UI_NAV_IDS.appAutomation, title: t("automation.nav.title"), path: tenantPath("automations"), icon: , permission: "automation.read" as const, }, ] : []), ...(hasFeatureAccess("crm-basic") ? [ { id: UI_NAV_IDS.appCrm, title: t("crm:title"), // R-P6: typed CRM contacts replace the entity-builder CRM (/crm → /contacts). path: tenantPath("contacts"), icon: , permission: "crm.read_own" as const, }, ] : []), ...(hasFeatureAccess("leads") ? [ { id: UI_NAV_IDS.appLeads, title: t("leads.nav.title"), path: tenantPath("leads"), icon: , permission: "leads.read_own" as const, }, ] : []), ...(hasFeatureAccess("projects") ? [ { id: UI_NAV_IDS.appProjects, title: t("projects.nav.title"), path: tenantPath("projects"), icon: , permission: "projects.read_own" as const, }, ] : []), ...(hasFeatureAccess("files") ? [ { id: "ui.nav.app.files", title: t("files.nav.title"), path: tenantPath("files"), icon: , permission: "files.read_own" as const, }, ] : []), ...(hasFeatureAccess("tasks") ? [ { id: "ui.nav.app.tasks", title: t("tasks.nav.title"), path: tenantPath("tasks"), icon: , permission: "tasks.read_own" as const, }, ] : []), ...(hasFeatureAccess("hr") ? [ { id: "ui.nav.app.hr", title: t("hr.nav.title"), path: tenantPath("hr"), icon: , permission: "hr.read_own" as const, }, ] : []), ...(hasFeatureAccess("integrations") ? [ { id: "ui.nav.app.integrations", title: t("integrations.nav.title"), path: tenantPath("integrations"), icon: , permission: "integrations.read" as const, }, ] : []), ...(hasFeatureAccess("integrations") ? [ { // AK-P16a · calendar reuses the integrations feature gate (it is an // Apps-Engine integration); the entry is gated by calendar.connect_own. id: UI_NAV_IDS.appCalendar, title: t("calendar.nav.title"), path: tenantPath("calendar"), icon: , permission: "calendar.connect_own" as const, }, ] : []), ...(hasFeatureAccess("email-inbox") ? [ { // VA-P23 · mailbox sync inbox — own `email-inbox` feature gate; the // entry is gated by email.read_own (own-mailbox visibility, M09 I). id: UI_NAV_IDS.appEmails, title: t("emailInbox.nav.title"), path: tenantPath("emails"), icon: , permission: "email.read_own" as const, }, ] : []), ...(hasFeatureAccess("booking") ? [ { // AK-P16b · Booking module — own `booking` feature gate; the entry is // gated by bookings.read_own (every provider can see their own bookings). id: UI_NAV_IDS.appBookings, title: t("bookings.nav.title"), path: tenantPath("bookings"), icon: , permission: "bookings.read_own" as const, }, ] : []), ...(hasFeatureAccess("forms") ? [ { id: UI_NAV_IDS.appForms, title: t("settings.forms.admin.title"), path: tenantPath("forms"), icon: , permission: "forms.basic" as const, }, ] : []), ...(hasFeatureAccess("email-marketing") ? [ { id: UI_NAV_IDS.appEmailMarketing, title: t("emailMarketing:title"), path: tenantPath("email-marketing"), icon: , }, ] : []), ...(hasFeatureAccess("workflow-engine") ? [ { id: UI_NAV_IDS.appWorkflowEngine, title: t("workflows.title"), path: tenantPath("workflow-engine"), icon: , }, ] : []), ...(hasFeatureAccess("api") ? [ { id: UI_NAV_IDS.appApi, title: t("models.apiKey.plural"), path: tenantPath("settings/api"), icon: , }, ] : []), ...(walkingSkeletonState !== "hidden" ? [ { id: "ui.nav.app.walkingSkeleton", title: t("walkingSkeleton.nav"), path: tenantPath("walking-skeleton"), icon: , disabled: walkingSkeletonState === "locked", }, ] : []), ]; const appItem: SideBarItem = { id: "ui.nav.app.primary", title: "", path: "", items: [ ...(hasDashboardAccess ? [ { id: UI_NAV_IDS.appDashboard, title: t("app.sidebar.dashboard"), path: tenantPath("dashboard"), icon: , permission: "dashboard.read" as const, // tenantUserTypes: [TenantUserType.OWNER, TenantUserType.ADMIN, TenantUserType.MEMBER], }, ] : []), { id: UI_NAV_IDS.appNotifications, title: t("app.sidebar.notifications"), path: tenantPath("notifications"), icon: , }, ...productCoreItems, // { // title: t("models.email.plural"), // path: `${currentTenantUrl}/emails`, // icon: SvgIcon.EMAILS, // }, ], }; return [ appItem, { id: "ui.nav.app.secondary", title: "", path: "", isSecondary: true, items: [ { id: UI_NAV_IDS.appSettings, title: t("app.sidebar.settings"), icon: , // tenantUserTypes: [TenantUserType.OWNER, TenantUserType.ADMIN], path: tenantPath("settings"), redirectTo: tenantPath("settings/profile"), }, // { // title: t("app.sidebar.logs"), // icon: SvgIcon.LOGS, // tenantUserTypes: [TenantUserType.OWNER, TenantUserType.ADMIN], // path: `${currentTenantUrl}/logs`, // }, { id: UI_NAV_IDS.appSwitchToAdmin, title: t("admin.switchToAdmin"), path: absoluteAdminPath(routing, "dashboard"), icon: , adminOnly: true, }, ], }, ]; }; // function SideText({ text }: { text: string }) { // return ( //
//
{text}
//
// ); // }