"use client";

import { FC, useEffect, useState } from "react";
import { getOverviewTicketsAction } from "app/_actions/overviews";

import { TicketList } from "./TicketList";

type ZammadOverviewProps = {
  name: string;
};

export const ZammadOverview: FC<ZammadOverviewProps> = ({ name }) => {
  const [tickets, setTickets] = useState([]);

  useEffect(() => {
    const fetchTickets = async () => {
      const { tickets } = await getOverviewTicketsAction(name);
      setTickets(tickets);
    };

    fetchTickets();

    const interval = setInterval(fetchTickets, 10000);

    return () => clearInterval(interval);
  }, [name]);

  return <TicketList title={name} tickets={tickets} />;
};
