// lib/api.ts
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000';

export const api = {
  // Employees
  async getEmployees() {
    const res = await fetch(`${API_BASE_URL}/api/employees`);
    if (!res.ok) throw new Error('Failed to fetch employees');
    return res.json();
  },

  async createEmployee(data: any) {
    const res = await fetch(`${API_BASE_URL}/api/employees`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(data),
    });
    if (!res.ok) throw new Error('Failed to create employee');
    return res.json();
  },

  // Departments
  async getDepartments() {
    const res = await fetch(`${API_BASE_URL}/api/departments`);
    if (!res.ok) throw new Error('Failed to fetch departments');
    return res.json();
  },
};