import { createContext, useContext } from 'react'
import type { PropsWithChildren } from 'react'

interface Link {
  target: string
  title: string
  url: string
}

interface GlobalSettingsSection {
  address: string
  contactEmail: string
  fax: string
  phone1: string
  phone2: string
  privacyPolicy: Link
  termsOfUse: Link
  uploadArtworkLink: Link
}

export type GlobalContextValue = {
  settings: any
  globalSettings: GlobalSettingsSection
  socialLinks: any
  headerMenu: any
  footerMenu: any
  newsletterForm: any
  preview: boolean
}

export type GlobalProviderProps = PropsWithChildren & {
  value: GlobalContextValue
}

const GlobalContext = createContext({
  settings: {},
  globalSettings: {},
  socialLinks: {},
  headerMenu: {},
  footerMenu: {},
  newsletterForm: {},
} as GlobalContextValue)

export function useGlobals() {
  return useContext(GlobalContext)
}

export function GlobalProvider({ value, children }: GlobalProviderProps) {
  return <GlobalContext.Provider value={value}>{children}</GlobalContext.Provider>
}
