import type { Meta, StoryObj } from '@storybook/angular';
import { Brief } from '@brief/domain/brief';
import { Diagnostic } from '@brief/domain/placeholders';
import { LetterPreviewComponent } from './letter-preview.component';

const brief: Brief = {
  briefId: 'b1',
  beroep: 'arts',
  templateId: 't1',
  drafterId: 'demo-drafter',
  status: { tag: 'draft' },
  placeholders: [
    { key: 'naam_zorgverlener', label: 'Naam zorgverlener', autoResolvable: true },
    { key: 'reden_besluit', label: 'Reden besluit', autoResolvable: false },
  ],
  sections: [
    {
      sectionKey: 'aanhef',
      title: 'Aanhef',
      required: true,
      locked: true,
      blocks: [
        {
          type: 'passage',
          blockId: 'local-1',
          sourcePassageId: 'p1',
          sourceVersion: 1,
          edited: false,
          content: {
            paragraphs: [
              {
                nodes: [
                  { type: 'text', text: 'Geachte heer/mevrouw ' },
                  { type: 'placeholder', key: 'naam_zorgverlener' },
                  { type: 'text', text: ',' },
                ],
              },
            ],
          },
        },
      ],
    },
    {
      sectionKey: 'kern',
      title: 'Kern van het besluit',
      required: true,
      locked: false,
      blocks: [
        {
          type: 'freeText',
          blockId: 'local-2',
          content: {
            paragraphs: [
              {
                nodes: [
                  { type: 'text', text: 'Wij hebben besloten om reden ' },
                  { type: 'placeholder', key: 'reden_besluit' },
                  { type: 'text', text: '.' },
                ],
              },
            ],
          },
        },
      ],
    },
  ],
};

const diagnostics: Diagnostic[] = [
  {
    severity: 'warning',
    code: 'unresolved-at-send',
    placeholderKey: 'reden_besluit',
    location: { blockId: 'local-2', paragraphIndex: 0, nodeIndex: 1 },
    message: '"Reden besluit" is nog niet ingevuld.',
  },
];

const meta: Meta<LetterPreviewComponent> = {
  title: 'Domein/Brief/Letter Preview',
  component: LetterPreviewComponent,
  args: { brief, diagnostics },
};
export default meta;
type Story = StoryObj<LetterPreviewComponent>;

export const Default: Story = {};
export const ZonderBevindingen: Story = { args: { diagnostics: [] } };
