import { useState, useEffect } from "react";
import { Entity } from "../types";

interface Position extends Entity {
  type: string;
  employeeCount: number;
  title: string;
}

interface UsePositionsData {
  positions: Position[];
  isLoading: boolean;
}

export const usePositionsData = (departmentId: string): UsePositionsData => {
  const [positions, setPositions] = useState<Position[]>([]);
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    const fetchData = async () => {
      setIsLoading(true);
      if (!departmentId) {
        setPositions([]);
        setIsLoading(false);
        return;
      }
      await new Promise((r) => setTimeout(r, 500));
      setPositions([
        {
          id: `${departmentId}-pos1`,
          name: {
            am: "Leader in Amharic",
            en: "Leader",
          },
          type: "Leader",
          employeeCount: 1,
          title: "Leader",
        },
      ]);
      setIsLoading(false);
    };
    fetchData();
  }, [departmentId]);

  return { positions, isLoading };
};
