import type { KeepAliveEntry } from '../types/keepAlive.types';
import { AdminDatabaseHealthPage } from '../pages/admin/AdminDatabaseHealthPage';
import { AdminLanguagesPage } from '../pages/admin/AdminLanguagesPage';
import { CommcoachSessionView } from '../pages/views/commcoach';
import { GraphicalEditorPage } from '../pages/views/graphicalEditor/GraphicalEditorPage';
import { WorkspacePage } from '../pages/views/workspace/WorkspacePage';

export const KEEP_ALIVE_ROUTES: KeepAliveEntry[] = [
  {
    id: 'workspace-dashboard',
    pathRegex: /\/mandates\/[^/]+\/workspace\/[^/]+\/dashboard/,
    scopeRegex: /\/mandates\/([^/]+)\/workspace\/([^/]+)/,
    requireMandateForMount: false,
    render: ({ mandateId, instanceId, scopeKey }) => (
      <WorkspacePage key={scopeKey} persistentInstanceId={instanceId} persistentMandateId={mandateId} />
    ),
  },
  {
    id: 'commcoach-session',
    pathRegex: /\/mandates\/[^/]+\/commcoach\/[^/]+\/session/,
    scopeRegex: /\/mandates\/([^/]+)\/commcoach\/([^/]+)\/session/,
    shellOverflowHidden: false,
    render: ({ scopeKey }) => <CommcoachSessionView key={scopeKey} />,
  },
  {
    id: 'graphical-editor',
    pathRegex: /\/mandates\/[^/]+\/graphicalEditor\/[^/]+\/editor/,
    scopeRegex: /\/mandates\/([^/]+)\/graphicalEditor\/([^/]+)\/editor/,
    render: ({ mandateId, instanceId, scopeKey }) => (
      <GraphicalEditorPage
        key={scopeKey}
        persistentInstanceId={instanceId}
        persistentMandateId={mandateId}
      />
    ),
  },
  {
    id: 'admin-languages',
    pathRegex: /\/admin\/languages(?:$|\/)/,
    render: () => <AdminLanguagesPage />,
  },
  {
    id: 'admin-database-health',
    pathRegex: /\/admin\/database-health(?:$|\/)/,
    render: () => <AdminDatabaseHealthPage />,
  },
];

export function hideFeatureOutlet(pathname: string): boolean {
  return KEEP_ALIVE_ROUTES.some((e) => e.pathRegex.test(pathname));
}
