import { ExperimentStatus } from '@/enums';
import LogList from '@/pages/Experiment/components/LogList';
import type { Meta, StoryObj } from '@storybook/react';
import { http, HttpResponse } from 'msw';
import { logData, logEmptyData, logGroupData } from '../mockData';

let count = 0;

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
  title: 'Pages/LogList 日志组',
  component: LogList,
  parameters: {
    // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
    // layout: 'centered',
    msw: {
      handlers: [
        http.post('/api/mmp/experimentIns/realTimeLog', () => {
          return HttpResponse.json(logGroupData);
        }),
        http.get('/api/mmp/experimentIns/pods/log', () => {
          if (count > 0) {
            count = 0;
            return HttpResponse.json(logEmptyData);
          }
          count += 1;
          return HttpResponse.json(logData);
        }),
      ],
    },
  },
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
  tags: ['autodocs'],
  // More on argTypes: https://storybook.js.org/docs/api/argtypes
  argTypes: {
    instanceNodeStatus: { control: 'select', options: Object.values(ExperimentStatus) },
  },
  // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
  // args: { onClick: fn() },
} satisfies Meta<typeof LogList>;

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

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
/** 运行完成时 */
export const Succeeded: Story = {
  args: {
    instanceName: 'workflow-txpb5',
    instanceNamespace: 'argo',
    pipelineNodeId: 'git-clone-05955a53',
    workflowId: 'workflow-txpb5-2484323670',
    instanceNodeStartTime: '2025-03-06 14:02:14',
    instanceNodeStatus: ExperimentStatus.Succeeded,
  },
};

/** 无状态，空数据 */
export const NoStatus: Story = {
  args: {
    instanceName: 'workflow-txpb5',
    instanceNamespace: 'argo',
    pipelineNodeId: 'git-clone-05955a53',
    workflowId: 'workflow-txpb5-2484323670',
    instanceNodeStartTime: '2025-03-06 14:02:14',
  },
};

/** Pending */
export const Pending: Story = {
  args: {
    instanceName: 'workflow-txpb5',
    instanceNamespace: 'argo',
    pipelineNodeId: 'git-clone-05955a53',
    workflowId: 'workflow-txpb5-2484323670',
    instanceNodeStartTime: '2025-03-06 14:02:14',
    instanceNodeStatus: ExperimentStatus.Pending,
  },
};

export const Running: Story = {
  args: {
    instanceName: 'workflow-txpb5',
    instanceNamespace: 'argo',
    pipelineNodeId: 'git-clone-05955a53',
    workflowId: 'workflow-txpb5-2484323670',
    instanceNodeStartTime: '2025-03-06 14:02:14',
    instanceNodeStatus: ExperimentStatus.Running,
  },
};
