import type { Meta, StoryObj } from '@storybook/react';
import { http, HttpResponse } from 'msw';
import { AdminSettingsView } from './AdminSettingsView';

/**
 * AdminSettingsView - Paramètres système
 *
 * Interface de configuration système avec feature flags,
 * mode maintenance et annonces globales.
 */
const meta: Meta<typeof AdminSettingsView> = {
    title: 'Components/Features/Admin/AdminSettingsView',
    component: AdminSettingsView,
    parameters: {
        layout: 'padded',
        docs: {
            description: {
                component: 'Configuration système admin avec feature flags et mode maintenance.',
            },
        },
    },
    tags: ['autodocs'],
    decorators: [
        (Story) => (
            <div className="bg-background min-h-screen p-4">
                <Story />
            </div>
        ),
    ],
};

export default meta;
type Story = StoryObj<typeof meta>;

/**
 * État par défaut des paramètres.
 */
export const Default: Story = {
    name: 'Par défaut',
};

/**
 * État de chargement.
 */
export const Loading: Story = {
    name: 'Chargement',
    parameters: {
        msw: {
            handlers: [
                http.get('*/api/v1/admin/maintenance', async () => {
                    await new Promise(() => {});
                    return HttpResponse.json({ maintenance_mode: false });
                }),
                http.get('*/api/v1/admin/feature-flags', async () => {
                    await new Promise(() => {});
                    return HttpResponse.json({ feature_flags: [] });
                }),
                http.get('*/api/v1/admin/announcements', async () => {
                    await new Promise(() => {});
                    return HttpResponse.json({ announcements: [] });
                }),
            ],
        },
        docs: {
            description: {
                story: 'Skeleton pendant le chargement des paramètres.',
            },
        },
    },
};

/**
 * État d'erreur.
 */
export const Error: Story = {
    name: 'Erreur',
    parameters: {
        msw: {
            handlers: [
                http.get('*/api/v1/admin/maintenance', () =>
                    HttpResponse.json({ error: 'Server error' }, { status: 500 })),
                http.get('*/api/v1/admin/feature-flags', () =>
                    HttpResponse.json({ error: 'Server error' }, { status: 500 })),
                http.get('*/api/v1/admin/announcements', () =>
                    HttpResponse.json({ error: 'Server error' }, { status: 500 })),
            ],
        },
        docs: {
            description: {
                story: 'Affichage en cas d\'échec du chargement.',
            },
        },
    },
};

/**
 * Annonces vides.
 */
export const EmptyAnnouncements: Story = {
    name: 'Sans annonces',
    parameters: {
        msw: {
            handlers: [
                http.get('*/api/v1/admin/announcements', () =>
                    HttpResponse.json({ announcements: [] })),
            ],
        },
        docs: {
            description: {
                story: 'Aucune annonce configurée.',
            },
        },
    },
};
