import React from 'react';
import { LLWidgetHeader } from '../LLWidgetHeader';
import { LLWidgetFooter } from '../LLWidgetFooter';
import { LLCoreWidget } from '../LLCoreWidget';
import {
  usePredictionClaimRewardEffect,
  useWidgetInteractiveTimeout,
} from '../../hooks';
import { LLBaseWidgetProps } from '../LLBaseWidgetProps';
import { LLPredictionFollowUpWidgetBody } from './LLPredictionFollowUpWidgetBody';
import { LLVoteWidgetBodyProps } from '../LLVoteWidgetBody';

export type LLPredictionFollowUpWidgetProps = LLBaseWidgetProps & {
  BodyComponent?: typeof LLPredictionFollowUpWidgetBody;
  BodyComponentStyles?: LLVoteWidgetBodyProps['styles'];
};

export function LLPredictionFollowUpWidget({
  programId,
  widgetId,
  widgetKind,
  onDismiss: onDismissProp,
  interactiveTimeout: interactiveTimeoutProp,
  onInteractiveTimeout: onInteractiveTimeoutProp,
  WidgetComponent = LLCoreWidget,
  HeaderComponent = LLWidgetHeader,
  BodyComponent = LLPredictionFollowUpWidgetBody,
  FooterComponent = LLWidgetFooter,
  WidgetComponentStyles,
  HeaderComponentStyles,
  BodyComponentStyles,
  FooterComponentStyles,
}: LLPredictionFollowUpWidgetProps) {
  const { interactiveTimeout, onInteractiveTimeout } =
    useWidgetInteractiveTimeout({
      widgetId,
      interactiveTimeout: interactiveTimeoutProp,
      onInteractiveTimeout: onInteractiveTimeoutProp,
    });
  usePredictionClaimRewardEffect({ widgetId, widgetKind });

  return (
    <WidgetComponent
      widgetId={widgetId}
      widgetKind={widgetKind}
      programId={programId}
      onDismiss={onDismissProp}
      styles={WidgetComponentStyles}
    >
      {({ widget, onDismiss }) => (
        <>
          <HeaderComponent
            title={widget.question}
            interactiveTimeout={interactiveTimeout}
            onInteractiveTimeout={onInteractiveTimeout}
            onDismiss={onDismiss}
            dismissable={!!onDismissProp}
            styles={HeaderComponentStyles}
          />
          <BodyComponent widgetId={widgetId} styles={BodyComponentStyles} />
          <FooterComponent styles={FooterComponentStyles} widgetId={widgetId} />
        </>
      )}
    </WidgetComponent>
  );
}
