import { View, ViewStyle } from "react-native";
import {
  CardWithIconWidget,
  CardWithListItemsWidget,
  ComparisonWidget,
  ExpandableListWidget,
  FAB,
  FooterWithCardWidget,
  GridWithCardWidget,
  HeaderLottieAnimationWidget,
  HeaderWithAssetsWidget,
  HeroSectionWidget,
  ListItemWidget,
  SelectCardWithDetailListWidget,
  SelectCardWithTagListItems,
  SliderWidget,
  SpacerWidget,
  SumInsuredWidget,
  TableWidget,
  TitleRightTitleWithContentListWidget,
  TitleSubtitleWithAssetWidget,
  TitleWidget,
  TitleWithAssetBackgroundWidget,
  TitleWithAssetsWidget,
  TitleWithColumnWidget,
  TitleWithHorizontalCarouselListWidget,
  TitleWithListWidget,
  SelectCardWithFooterWidget,
} from "../../../components/widgets";
import { GenericActionPayload } from "../actions/GenericAction";
import {
  CARD_WITH_ICON_WIDGET,
  CARD_WITH_LIST_ITEMS_WIDGET,
  COMPARISON_WIDGET,
  EXPANDABLE_LIST_WIDGET,
  FAB_REQUEST_TO_CALLBACK,
  FOOTER_WITH_CARD_WIDGET,
  GRID_WITH_CARD_WIDGET,
  HEADER_LOTTIE_ANIMATION_WIDGET,
  HEADER_WITH_ASSETS_WIDGET,
  HERO_SECTION_WIDGET,
  LIST_ITEM_WITH_ICON_WIDGET,
  SELECT_CARD_WITH_DETAIL_LIST_WIDGET,
  SLIDER_WIDGET,
  SPACER_WIDGET,
  SUM_INSURED_WIDGET,
  TABLE_WIDGET,
  TITLE_RIGHT_TITLE_WITH_CONTENT_LIST_WIDGET,
  TITLE_SUBTITLE_WITH_ASSET_WIDGET,
  TITLE_WIDGET,
  TITLE_WITH_ASSETS_WIDGET,
  TITLE_WITH_ASSET_BACKGROUND_WIDGET,
  TITLE_WITH_COLUMN_WIDGET,
  TITLE_WITH_LIST_WIDGET,
  TITLE_WITH_HORIZONTAL_CAROUSEL_LIST_WIDGET,
  SELECT_CARD_WITH_TAG_LIST_ITEMS_WIDGET,
  SELECT_CARD_WITH_FOOTER_WIDGET,
} from "../constants";
import { CtaData } from "../interface";
import { GenericWidgetData, Widget } from "../interface/widgets/Widget";
import { SumInsuredWidgetData } from "../interface/widgets/widgetData/SumInsuredWidgetData";
import { ScreenState } from "../screen/BaseScreen";
import React from "react";

export const GetWidgetView = {
  getWidget: (
    widget: Widget,
    handleActions: (
      value?: any | undefined | null,
      actionPayload?: GenericActionPayload,
    ) => void,
    widgetIndex: number,
    handleClick?: (ctaData: CtaData) => void,
    screenState?: ScreenState | null,
  ): JSX.Element => {
    const { widgetName, widgetData, widgetStyle, widgetId } = widget;
    return resolveWidgetView(
      widgetId,
      widgetName,
      widgetData,
      widgetStyle,
      handleActions,
      widgetIndex,
      handleClick,
      screenState,
    );
  },
};
function resolveWidgetView(
  widgetId: string,
  widgetName: string,
  widgetData: GenericWidgetData,
  widgetStyle: ViewStyle,
  handleActions: (
    value?: any | undefined | null,
    screenActionPayload?: GenericActionPayload,
  ) => void,
  widgetIndex: number,
  handleClick?: (ctaData: CtaData) => void,
  screenState?: ScreenState | null,
) {
  switch (widgetName) {
    case SLIDER_WIDGET:
      return (
        <SliderWidget
          widgetData={widgetData}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
        />
      );
    case TITLE_WIDGET:
      return (
        <TitleWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          handleClick={handleClick}
          widgetIndex={widgetIndex}
          key={widgetIndex}
        />
      );
    case SUM_INSURED_WIDGET:
      return (
        <SumInsuredWidget
          widgetData={widgetData}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={
            widgetIndex +
            "_" +
            (widgetData as SumInsuredWidgetData).carouselListData?.length!!
          }
        />
      );
    case TITLE_WITH_LIST_WIDGET:
      return (
        <TitleWithListWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case COMPARISON_WIDGET:
      return (
        <ComparisonWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case TITLE_WITH_ASSETS_WIDGET:
      return (
        <TitleWithAssetsWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case FOOTER_WITH_CARD_WIDGET:
      return (
        <FooterWithCardWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
          screenState={screenState}
        />
      );
    case HEADER_WITH_ASSETS_WIDGET:
      return (
        <HeaderWithAssetsWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case HEADER_LOTTIE_ANIMATION_WIDGET:
      return (
        <HeaderLottieAnimationWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case GRID_WITH_CARD_WIDGET:
      return (
        <GridWithCardWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          handleClick={handleClick}
          widgetIndex={widgetIndex}
          key={widgetIndex}
        />
      );
    case TITLE_SUBTITLE_WITH_ASSET_WIDGET:
      return (
        <TitleSubtitleWithAssetWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          handleClick={handleClick}
          widgetIndex={widgetIndex}
          key={widgetIndex}
        />
      );
    case FAB_REQUEST_TO_CALLBACK:
      return (
        <FAB
          widgetData={widgetData}
          handleActions={handleActions}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case TITLE_WITH_COLUMN_WIDGET:
      return (
        <TitleWithColumnWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          handleClick={handleClick}
          widgetIndex={widgetIndex}
        />
      );
    case TITLE_WITH_ASSET_BACKGROUND_WIDGET:
      return (
        <TitleWithAssetBackgroundWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
        />
      );
    case CARD_WITH_ICON_WIDGET:
      return (
        <CardWithIconWidget
          widgetData={widgetData}
          handleActions={handleActions}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case SPACER_WIDGET:
      return (
        <SpacerWidget
          widgetData={widgetData}
          handleActions={handleActions}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case SELECT_CARD_WITH_DETAIL_LIST_WIDGET:
      return (
        <SelectCardWithDetailListWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case TABLE_WIDGET:
      return (
        <TableWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case HERO_SECTION_WIDGET:
      return (
        <HeroSectionWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case LIST_ITEM_WITH_ICON_WIDGET:
      return (
        <ListItemWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );

    case CARD_WITH_LIST_ITEMS_WIDGET:
      return (
        <CardWithListItemsWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetId + widgetIndex}
          handleClick={handleClick}
          screenState={screenState}
        />
      );

    case TITLE_WITH_HORIZONTAL_CAROUSEL_LIST_WIDGET:
      return (
        <TitleWithHorizontalCarouselListWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          handleClick={handleClick}
          widgetIndex={widgetIndex}
          key={widgetIndex}
        />
      );

    case TITLE_RIGHT_TITLE_WITH_CONTENT_LIST_WIDGET:
      return (
        <TitleRightTitleWithContentListWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case SELECT_CARD_WITH_TAG_LIST_ITEMS_WIDGET:
      return (
        <SelectCardWithTagListItems
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case EXPANDABLE_LIST_WIDGET:
      return (
        <ExpandableListWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex}
          handleClick={handleClick}
        />
      );
    case SELECT_CARD_WITH_FOOTER_WIDGET:
      return (
        <SelectCardWithFooterWidget
          widgetData={widgetData}
          widgetStyle={widgetStyle}
          handleActions={handleActions}
          widgetIndex={widgetIndex}
          key={widgetIndex + widgetId}
          handleClick={handleClick}
        />
      );
    default:
      return <View />;
  }
}
