import Header from "../components/Header"; import { google } from "googleapis"; const auth = new google.auth.GoogleAuth({ credentials: { client_email: process.env.GOOGLE_CLIENT_EMAIL, private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'), project_id: process.env.GOOGLE_PROJECT_ID, }, scopes: ['https://www.googleapis.com/auth/spreadsheets.readonly'], }); async function fetchSheetData(spreadsheetId, range) { const client = await auth.getClient(); const sheets = google.sheets('v4'); const response = await sheets.spreadsheets.values.get({ auth: client, spreadsheetId, range, }); const rows = response.data.values; // Define the headers const headers = [ 'CompanyID', 'Businesses', 'ParentCompany', 'Type', 'Owner', 'Status', 'Notes' ]; // Map rows to objects const formattedData = rows.slice(1).map(row => { const obj = {}; headers.forEach((header, index) => { let value = row[index] || ''; // Assign empty string if value is missing if (header === 'Businesses') { value = value.includes('\n') ? value.split('\n') : [value]; // Split into array if multiple businesses } obj[header] = value; }); return obj; }); return Object.values( formattedData.reduce((acc, company) => { const parent = company.ParentCompany; if (!acc[parent]) { acc[parent] = {...company, Businesses: [...company.Businesses]}; } else { acc[parent].Businesses = [...acc[parent].Businesses, ...company.Businesses]; } return acc; }, {}) ); } export const metadata = { title: 'Enterprises', description: 'Registered enterprises in the Alure Regions', } export default async function Services() { const response = await fetchSheetData('1VWt21lvbqBRmpZPeC87ZXJphibMEATFp48PPW457q38', 'A1:G32'); return (

Want to start a business?

Register with the Alure Regions government in order to operate a company.

{/*
*/}
{ response.map((company) => { return (

{company.ParentCompany}

Business ID: {company.CompanyID} • Owner: {company.Owner}

Type: {company.Type}

Status: Operational

Businesses

    { company.Businesses.map((business) => { return (
  • {business}
  • ) }) }
{ company.Notes && ( <>

Notes:

{company.Notes}

) }
) }) }
) }