import fs from "fs"
import path from "path"
import { jsonFileNames } from "./devJsonFileNames"

const fileName = jsonFileNames.namVibentec

async function readDesignFile() {
  const filePath = path.join(process.cwd(), "config", fileName)
  const fileData = await fs.promises.readFile(filePath, "utf-8")
  return JSON.parse(fileData)
}


export async function loadLayoutConfig() {
  const config = await readDesignFile()
  if (Array.isArray(config)) return config
  return config.layout ?? []
}

export async function loadPageConfig(pageKey: string) {
  const config = await readDesignFile()
  if (Array.isArray(config)) return []
  const pages = config.pages ?? {}
  return pages[pageKey] ?? []
}

export async function loadDesignConfig() {
  return loadLayoutConfig()
}
