import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { getSetting } from '@/lib/services/settings.service';

export const GET = withAuth(
  withPermission('documents', 'view', async (_req, ctx) => {
    try {
      const showExpired = await getSetting('documents_show_expired_tab', ctx.portId);
      return NextResponse.json({
        data: {
          showExpiredTab: showExpired?.value !== false, // default true
        },
      });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
