/* eslint-disable @typescript-eslint/no-explicit-any */

import { generateGlobalData } from "./generateGlobalData"
import { generateCurrentPageInfo, generatePageInfos } from "./generatePageInfo"
import { generateRawWidget } from "./generateRawWidget"


export const CURRENT_USER_INFO_ACCESS_LIST_KEY = [
  "userID",
  "nickname",
  "email",
  "avatar",
  "language",
  "createdAt",
  "updatedAt",
]

export class RawTreeFactory {
  static create(seeds: any): any {
    const { widgets, globalData } = seeds
    const rawTree: any = {} as any
    Object.keys(widgets).forEach((key) => {
      rawTree[key] = generateRawWidget(widgets[key])
    })

    // const customStorage = localStorage[CUSTOM_STORAGE_PREFIX]

    // const canShownUserInfo: CurrentUserInfoInTree = Object.keys(
    //   currentUserInfo,
    // ).reduce((acc, key) => {
    //   if (
    //     CURRENT_USER_INFO_ACCESS_LIST_KEY.includes(key) &&
    //     currentUserInfo[key as keyof typeof currentUserInfo]
    //   ) {
    //     acc[key as keyof CurrentUserInfoInTree] = currentUserInfo[
    //       key as keyof typeof currentUserInfo
    //     ] as string
    //   }
    //   return acc
    // }, {} as CurrentUserInfoInTree)

    // rawTree.builderInfo = builderInfo
    // rawTree.currentUserInfo = canShownUserInfo
    rawTree.globalData = generateGlobalData(globalData)
    // rawTree.urlParams = generateUrlParams()
    // rawTree.localStorage = customStorage ? JSON.parse(customStorage) : {}
    rawTree.currentPageInfo = generateCurrentPageInfo()
    rawTree.pageInfos = generatePageInfos(widgets)
    return rawTree
  }
}
