import { apiGetShipTypes } from '@/services/slave/sgw/ShipController';
import { useCallback, useState } from 'react';

export default function useShipTypes() {
  const [shipTypes, setShipTypes] = useState<SgwModel.ShipType[] | null>(null);
  const [loading, setLoading] = useState(false);

  const getShipTypes = useCallback(async () => {
    setLoading(true);
    try {
      const res = await apiGetShipTypes(); // đổi URL cho phù hợp
      setShipTypes(res || null);
    } catch (err) {
      console.error('Fetch ShipTypes failed', err);
    } finally {
      setLoading(false);
    }
  }, []);

  return {
    shipTypes,
    loading,
    getShipTypes,
  };
}
