import type {Meta, StoryObj} from '@storybook/angular';
import {moduleMetadata} from '@storybook/angular';
import {Chatbot} from './chatbot';
import {Store, StoreModule} from '@ngrx/store';
import {reducers} from '../reducers';
import {ConversationsService} from '../services/conversations.service';
import {ApiService} from '../services/api-service';
import {HttpClientModule} from '@angular/common/http';
import {TranslationService} from '../services/translation.service';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {PromptInput} from './prompt-input/prompt-input';
import {MessageBox} from './message-box/message-box';
import {NewInput} from './new-input/new-input';
import {FeedbackButton} from './feedback-button/feedback-button';
import {WarningBugs} from './warning-bugs/warning-bugs';
import {VersionInfos} from './version-infos/version-infos';
import {LoadingNotification} from './loading-notification/loading-notification';
import {SourceBlock} from './source-block/source-block';
import {ToolsOptions} from './tools-options/tools-options';

const appReducer = reducers.app;

const meta: Meta<Chatbot> = {
  title: 'App/Features/Chatbot',
  component: Chatbot,
  tags: ['autodocs'],
  decorators: [
    moduleMetadata({
      imports: [
        CommonModule,
        FormsModule,
        HttpClientModule,
        StoreModule.forRoot({app: appReducer as any}),
        PromptInput,
        MessageBox,
        NewInput,
        FeedbackButton,
        WarningBugs,
        VersionInfos,
        LoadingNotification,
        SourceBlock,
        ToolsOptions,
      ],
      providers: [
        ConversationsService,
        ApiService,
        TranslationService,
        Store
      ]
    })
  ],
  parameters: {
    layout: 'fullscreen',
  }
};

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

export const Default: Story = {
  args: {
    // Les propriétés sont injectées par les services
  }
};

export const DemoMode: Story = {
  args: {
    // Les propriétés sont injectées par les services
  },
  parameters: {
    store: {
      init: (store: Store) => {
        store.dispatch({
          type: 'UPDATE_APP',
          payload: {
            demoMode: true,
            displayConversationListPanelLarge: true,
            displaySourcesPanelLarge: true
          }
        });
      }
    }
  }
};

export const CompactView: Story = {
  args: {
    // Les propriétés sont injectées par les services
  },
  parameters: {
    store: {
      init: (store: Store) => {
        store.dispatch({
          type: 'UPDATE_APP',
          payload: {
            demoMode: true,
            displayConversationListPanelLarge: false,
            displaySourcesPanelLarge: false
          }
        });
      }
    }
  }
};
