import { useState, useEffect, useCallback } from "react";
import axios from "axios";
import { Site } from "@/app/types";

const useSite = () => {
    const [site, setSite] = useState<Site>({
        id: "",
        name: "",
        description: "",
        networks: []
    });
    const [siteId, setSiteId] = useState("");

    const loadSite = useCallback(() => {
        if (!siteId) return;
        axios.get('/api/sites/get', {
            params: { siteId }
        }).then((response) => {
            setSite(response.data.site);
        });
    }, [siteId]);

    useEffect(() => {
        loadSite();
    }, [loadSite]);

    return {
        site,
        loadSite,
        setSiteId,
    };
};

export default useSite;