const getBanners = async function getBanners() {
    const config = useRuntimeConfig();
    const res = await $fetch(config.public.apiBase + '/home_page_banner_data.json')
        .catch((error) => error.data);
    // console.log(res);
    var result: BannerModel[] = [];
    if (res) {
        for (var i in res) {
            let item: BannerModel = {
                title: res[i].title ? res[i].title : "",
                sub_title: res[i].sub_title ? res[i].sub_title : "",
                body: res[i].body ? res[i].body : "",
                type: res[i].type ? res[i].type : "",
                image: res[i].image ? res[i].image : "",
                video: res[i].video ? res[i].video : "",
                link_text: res[i].link_text ? res[i].link_text : "",
                link_url: res[i].link_text_url ? res[i].link_url : "",
            };
            result.push(item);
        }
    }
    return result;
}

const getPartners = async function getPartners() {
    const config = useRuntimeConfig();
    var res = await $fetch(config.public.apiBase + '/home_page_partner_data.json')
        .catch((error) => error.data);
    // console.log(res);
    var result: PartnerModel[] = [];
    if (res) {
        for (var i in res) {
            var item: PartnerModel = {
                title: res[i].title ? res[i].title : "",
                image: res[i].image ? res[i].image : "",
                link_url: res[i].link_text_url ? res[i].link_url : "",
            };
            result.push(item);
        }
    }
    return result;
}

const getTestimonials = async function getTestimonials() {
    const config = useRuntimeConfig();
    const res = await $fetch(config.public.apiBase + '/home_page_testimonials_data.json')
        .catch((error) => error.data);
    // console.log(res);
    var result: TestimonialModel[] = [];
    if (res) {
        for (var i in res) {
            let item: TestimonialModel = {
                name: res[i].name ? res[i].name : "",
                profile_image: res[i].profile_image ? res[i].profile_image : "",
                company: res[i].company ? res[i].company : "",
                designation: res[i].designation ? res[i].designation : "",
                description: res[i].description ? res[i].description : "",
            };
            result.push(item);
        }
    }
    return result;
}

const getPageData = async function getPageData(url: string) {
    const config = useRuntimeConfig();
    const res = await $fetch(config.public.apiBase + url)
        .catch((error) => {
            console.log(error);
            console.log(error.data);
        });
    console.log(res);
    // var data = {};
    // if (res && res.layout && res.layout.sections) {
    //     for (var i = 0; i < res.layout.sections.length; i++) {
    //         var sec = res.layout.sections[i];
    //         var section = {};
    //         if (sec.sectionType) {
    //             section.sectionType = sec.sectionType;
    //             if (sec.blocks) {
    //                 for (var i = 0; i < sec.blocks.length; i++) {

    //                 }
    //             }
    //         }
    //     }
    // }
    return res;
}

export default {
    getBanners: getBanners,
    getPartners: getPartners,
    getTestimonials: getTestimonials,
    getPageData: getPageData,
    home: "home"
}