/* eslint-disable react/no-unstable-nested-components */
import type { Meta, StoryObj } from '@storybook/react';

import AppAnnouncement from '@pega/react-sdk-components/lib/components/widget/AppAnnouncement';

import {{COMPONENT_CLASS_NAME}} from './index';
import { pyHome1Resolved, pyHome1Raw } from './mock';

const meta: Meta<typeof {{COMPONENT_CLASS_NAME}}> = {
  title: '{{COMPONENT_CLASS_NAME}}',
  component: {{COMPONENT_CLASS_NAME}},
  excludeStories: /.*Data$/
};

export default meta;
type Story = StoryObj<typeof {{COMPONENT_CLASS_NAME}}>;

export const Base{{COMPONENT_CLASS_NAME}}: Story = args => {
  const configProps = pyHome1Resolved.children[0].children[0].config;

  const props = {
    getPConnect: () => {
      return {
        getStateProps: () => {
          return {};
        },
        getActionsApi: () => {
          return {
            getNextWork: () => {
              return new Promise(resolve => {
                resolve({});
              });
            },
            updateFieldValue: () => {
              /* nothing */
            },
            triggerFieldChange: () => {
              /* nothing */
            }
          };
        },
        getChildren: () => {
          return pyHome1Raw.children;
        },
        getComponentName: () => {
          return '';
        },
        getLocalizedValue: value => {
          return value;
        },
        getRawMetadata: () => {
          return pyHome1Raw;
        },
        createComponent: config => {
          if (config.type === 'AppAnnouncement') {
            return (
              <AppAnnouncement
                key='announcement'
                header='Announcements'
                description={configProps.description}
                datasource={configProps.datasource}
                whatsnewlink={configProps.whatsnewlink}
                getPConnect={(): typeof PConnect => ({}) as typeof PConnect}
              />
            );
          }
        },
        ignoreSuggestion: () => {
          /* nothing */
        },
        acceptSuggestion: () => {
          /* nothing */
        },
        setInheritedProps: () => {
          /* nothing */
        },
        resolveConfigProps: () => {
          /* nothing */
        }
      };
    }
  };

  const regionAChildren = pyHome1Raw.children[0].children.map(child => {
    return props.getPConnect().createComponent(child);
  });

  return (
    <{{COMPONENT_CLASS_NAME}} {...props} {...args}>
      {regionAChildren}
    </{{COMPONENT_CLASS_NAME}}>
  );
};

Base{{COMPONENT_CLASS_NAME}}.args = {};
