import { useState } from 'react';
import { supabase } from '@/integrations/supabase/client';

export function useCallLogStatus() {
  const [isLoading, setIsLoading] = useState(false);
  const [error, setError] = useState(null);

  const updateCallStatus = async (callLogId, newStatus) => {
    setIsLoading(true);
    setError(null);
    try {
      const { data, error } = await supabase
        .from('call_logs')
        .update({ 
          call_type: newStatus,
          updated_at: new Date().toISOString()
        })
        .eq('id', callLogId)
        .select()
        .single();
      if (error) throw error;
      return { success: true, data };
    } catch (err) {
      setError(err);
      return { success: false, error: err };
    } finally {
      setIsLoading(false);
    }
  };

  return { updateCallStatus, isLoading, error };
}
