/**
 * C-FE — /maintenance — list + manage maintenance windows.
 *
 * Server component shell: pulls the session role server-side to
 * decide whether to surface the "New window" button + delete actions.
 * Read access is universal among authenticated users; writes are
 * ADMIN/EDITOR (enforced server-side in the CRUD API regardless).
 */
import { getServerSession } from 'next-auth';
import { redirect } from 'next/navigation';
import { authOptions } from '@/lib/auth';
import { MaintenanceList } from '@/components/maintenance/MaintenanceList';

// react-doctor: nextjs-missing-metadata
export const metadata = {
    title: 'Maintenance — Uptime Sentinel',
    description: 'Scheduled maintenance windows and active suppressions',
};


export default async function MaintenancePage() {
    const session = await getServerSession(authOptions);
    if (!session?.user?.id) {
        redirect('/login');
    }

    const role = (session!.user as { role?: string }).role || '';
    const canWrite = ['ADMIN', 'EDITOR'].includes(role);

    return (
        <div className="p-6 max-w-7xl mx-auto">
            <MaintenanceList canWrite={canWrite} />
        </div>
    );
}
