'use client'

import React from 'react'
import {
  type ExpandedFooterConfig,
  type FooterConfig,
  config,
  expandedConfig,
  extendExpandedFooter,
  extendFooter,
} from '../config'

type Context = {
  config: FooterConfig
  expandedConfig: ExpandedFooterConfig
}
export const FooterConfigContext = React.createContext<Context>({
  config,
  expandedConfig,
})

export type Props = {
  extraConfig?: Partial<FooterConfig>
  extraExpandedConfig?: ExpandedFooterConfig
}
export function FooterConfigContextProvider({
  extraConfig,
  extraExpandedConfig,
  children,
}: React.PropsWithChildren<Props>) {
  const config = React.useMemo(() => extendFooter(extraConfig), [extraConfig])
  const expandedConfig = React.useMemo(
    () => extendExpandedFooter(extraExpandedConfig),
    [extraExpandedConfig],
  )

  return (
    <FooterConfigContext.Provider value={{ config, expandedConfig }}>
      {children}
    </FooterConfigContext.Provider>
  )
}
