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

const meta = {
    title: 'Components/Features/Chat/ChatSidebar',
    component: ChatSidebar,
    tags: ['autodocs'],
    parameters: {
        layout: 'centered',
    },
    decorators: [
        (Story) => (
            <div className="w-80 min-h-layout-page border rounded-lg overflow-hidden bg-card border-border">
                <Story />
            </div>
        ),
    ],
} satisfies Meta<typeof ChatSidebar>;

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

export const Default: Story = {};

/** No conversations — empty state */
export const Empty: Story = {
    parameters: {
        msw: {
            handlers: [
                http.get('*/api/v1/conversations', () =>
                    HttpResponse.json({ success: true, data: [] }),
                ),
            ],
        },
    },
};

/** API error — error state with retry */
export const Error: Story = {
    parameters: {
        msw: {
            handlers: [
                http.get('*/api/v1/conversations', () =>
                    HttpResponse.json(
                        { success: false, error: { message: 'Signal lost' } },
                        { status: 500 },
                    ),
                ),
            ],
        },
    },
};
