'use client'

import React from 'react'

type Context = {
  expanded: boolean
  toggle: () => void
}
export const ExpandedFooterContext = React.createContext<Context>({
  expanded: false,
  toggle: () => {},
})

type Props = {
  isInitiallyExpanded?: boolean
}
export function ExpandedFooterContextProvider({
  isInitiallyExpanded = false,
  children,
}: React.PropsWithChildren<Props>) {
  const [expanded, setExpanded] = React.useState<boolean>(isInitiallyExpanded)

  const toggle = React.useCallback(
    () => setExpanded((prevExpanded) => !prevExpanded),
    [],
  )

  return (
    <ExpandedFooterContext.Provider value={{ expanded, toggle }}>
      {children}
    </ExpandedFooterContext.Provider>
  )
}
