import { EActivity } from '@src/constants/Enums';
import { IActivity } from 'metarare';
import { useEffect, useState } from 'react';

interface IOwnProps {
  activity: IActivity[];
}

const useActivityFilter = ({ activity }: IOwnProps) => {
  const [activityList, setActivityList] = useState<IActivity[]>([]);
  const [selectedActivityFilter, setSelectedActivityFilter] = useState<EActivity[]>([]);

  useEffect(() => {
    const list = activity.filter(item => {
      if (!selectedActivityFilter.length) {
        return true;
      }

      return selectedActivityFilter.includes(item.log_type);
    });

    setActivityList(list);
  }, [selectedActivityFilter, activity]);

  return {
    activityList,
    setSelectedActivityFilter,
    selectedActivityFilter
  };
};

export default useActivityFilter;
