'use server'

import { API_URL, TOKEN } from "@/utils/constants/selectConstants";

export async function getPlansHome(estadosId: string) {
    try {
        let url = 'Coberturas/BuscarCoberturasComPreco';
        let params = estadosId ? `?Valores=true&RetornarSoCobertura=1&order=Ordem&EstadosId=${estadosId}` : `?Valores=true&RetornarSoCobertura=1&order=Ordem`;

        const response = await fetch(`${API_URL}${url}${params}`, {
            headers: {
                Authorization: TOKEN
            }
        });

        const data = await response.json(); 
        return data; 
    } catch (error) {
        console.log('Erro ao buscar coberturas.', error);
        throw error; 
    }
}
