import type { Actions, PageServerLoad } from './$types';
import { fail } from '@sveltejs/kit';
import { deleteSubmission, listSubmissions } from '$lib/server/submissions';

export const load: PageServerLoad = () => {
  return { submissions: listSubmissions() };
};

export const actions: Actions = {
  delete: async ({ request }) => {
    const form = await request.formData();
    const id = String(form.get('id') ?? '');
    if (!id) return fail(400, { error: 'ID mancante.' });
    deleteSubmission(id);
    return { success: true };
  }
};
