import { create } from 'zustand';
import { prafrotService } from '../services/prafrotService';
import { toast } from 'sonner';

export const useDrivers = create((set, get) => ({
  drivers: [],
  loading: false,
  error: null,

  fetchDrivers: async () => {
    set({ loading: true, error: null });
    try {
      const data = await prafrotService.getDrivers();
      set({ drivers: Array.isArray(data) ? data : (data.data || []) });
    } catch (error) {
      set({ error: error.message });
      toast.error('Erro ao carregar motoristas: ' + error.message);
    } finally {
      set({ loading: false });
    }
  }
}));
