import React from 'react';
import { LLWidgetHeader } from '../LLWidgetHeader';
import { LLWidgetFooter } from '../LLWidgetFooter';
import {
  useWidgetInteractiveTimeout,
  useWidgetExpiryEffect,
} from '../../hooks';
import { LLCoreWidget } from '../LLCoreWidget';
import { LLBaseWidgetProps } from '../LLBaseWidgetProps';
import {
  LLEmojiSliderWidgetBody,
  LLEmojiSliderWidgetBodyProps,
} from './LLEmojiSliderWidgetBody';
import { LLEmojiSliderWidgetActionInfo } from './LLEmojiSliderWidgetActionInfo';
import { WidgetKind } from '@livelike/javascript';

export type LLEmojiSliderWidgetProps = Omit<LLBaseWidgetProps, 'widgetKind'> & {
  BodyComponent?: typeof LLEmojiSliderWidgetBody;
  BodyComponentStyles?: LLEmojiSliderWidgetBodyProps['styles'];
};

export function LLEmojiSliderWidget({
  programId,
  widgetId,
  onDismiss: onDismissProp,
  interactiveTimeout: interactiveTimeoutProp,
  onInteractiveTimeout: onInteractiveTimeoutProp,
  WidgetComponent = LLCoreWidget,
  HeaderComponent = LLWidgetHeader,
  BodyComponent = LLEmojiSliderWidgetBody,
  FooterComponent = LLWidgetFooter,
  WidgetComponentStyles,
  HeaderComponentStyles,
  BodyComponentStyles,
  FooterComponentStyles,
}: LLEmojiSliderWidgetProps) {
  const { interactiveTimeout, onInteractiveTimeout } =
    useWidgetInteractiveTimeout({
      widgetId,
      interactiveTimeout: interactiveTimeoutProp,
      onInteractiveTimeout: onInteractiveTimeoutProp,
    });
  useWidgetExpiryEffect({ widgetId });

  return (
    <WidgetComponent
      widgetId={widgetId}
      widgetKind={WidgetKind.EMOJI_SLIDER}
      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}
            ActionInfoComponent={LLEmojiSliderWidgetActionInfo}
          />
        </>
      )}
    </WidgetComponent>
  );
}
