import { useState } from 'react';
import { DateRangeFilterState } from '../state';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { DateRangeFilterMode, Filter, RangeItem } from '@wix/bex-core';
import { useFilterToolbarState } from '../providers';

export interface UseDateRangeFilterStateParams {
  filter: Filter<RangeItem<Date>>;
  filterByTime?: boolean;
  mode?: DateRangeFilterMode;
}

export function useDateRangeFilterState(params: UseDateRangeFilterStateParams) {
  const { filter, filterByTime, mode } = params;

  const { translate } = useWixPatternsContainer();
  const toolbar = useFilterToolbarState();

  const [state] = useState(
    () =>
      new DateRangeFilterState({
        translate,
        filter,
        toolbar,
        filterByTime,
        mode,
      }),
  );

  return state;
}
