import { ref } from "vue";
import { getCompany } from "../services/company";
import {useAuthStore} from '../stores/auth'
import { useCompanyStore } from "../stores/company";


export default function useCompany() {

    const auth = useAuthStore();
    const companyStore = useCompanyStore();

    const loading = ref(false);
    const company = ref(null);

    const getCompanyData = async() => {
        if(companyStore.company === null) {
            loading.value = true;
            const companyId = auth.user.company;
            console.log(companyId)
            const resp = await getCompany(companyId);
            companyStore.company = resp;
            company.value = resp;
            loading.value = false;
        } else {
            company.value = companyStore.company;
        }
    }

    return {
        getCompanyData,
        loading,
        company
    }
}