import { useState, useCallback } from 'react';

/**
 * @typedef {Object} Employee
 * @property {number} id
 * @property {string} name
 * @property {string} type
 * @property {string} date
 * @property {string} status
 */

/**
 * Hook customizado para gestão de colaboradores/solicitações (Padrão Integra Finance).
 */
export const useEmployees = (initialData = []) => {
  const [employees, setEmployees] = useState(initialData);

  const addEmployeeRequest = useCallback((newData) => {
    setEmployees((prev) => [
      ...prev,
      { ...newData, id: prev.length > 0 ? Math.max(...prev.map(e => e.id)) + 1 : 1 }
    ]);
  }, []);

  const updateEmployeeRequest = useCallback((id, updatedData) => {
    setEmployees((prev) => 
      prev.map((e) => (e.id === id ? { ...e, ...updatedData } : e))
    );
  }, []);

  const deleteEmployeeRequest = useCallback((id) => {
    setEmployees((prev) => prev.filter((e) => e.id !== id));
  }, []);

  return {
    employees,
    addEmployeeRequest,
    updateEmployeeRequest,
    deleteEmployeeRequest,
    setEmployees
  };
};
