import { ref } from "vue";
import { getCompanies } from '../services/public';

export default function useDirecty() {
    const companies = ref([]);
    const loading = ref(false);

    const getCompaniesData = async(filterQuery) => {
        let filterArr = Object.values(filterQuery);
        let cleanfilterArr =  filterArr.filter(n=>n);
        let filterStr = "";

        if(cleanfilterArr.length >0){
            filterStr = cleanfilterArr[0] + "?"
            filterStr += cleanfilterArr.slice(1).join("&");
        }

        loading.value = true;
        const resp = await getCompanies(filterStr);
        companies.value = resp;
        loading.value = false;
    }

    return {
        getCompaniesData,
        loading,
        companies
    }
}