'use server'

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

export async function postLeadsEmpresas(data: {
    Empresa: string;
    CNPJ: string;
    Responsavel: string;
    Setor: string;
    Email: string;
    Telefone: string;
    Utm?: {
        UtmSource?: string;
        UtmCampaign?: string;
        UtmTerm?: string;
        UtmMedium?: string;
        UtmContent?: string;
    };
}) {
    try {
        const url = `${API_URL}LeadsEmpresas/InserirLead`;

        const response = await fetch(url, {
            method: 'POST',
            headers: {
                Authorization: TOKEN,
                'Content-Type': 'application/json',
                LocalAcesso: 'Site'
            },
            body: JSON.stringify({ Dados: [data] }),
        });

        const result = await response.json();
        return result;
    } catch (error) {
        console.error('Erro ao realizar o POST:', error);
        throw error;
    }
}