import React from 'react'
import { GridPrivateSettingsContext } from './context'
import type { GridPrivateSettingsContextType } from './types'

export type GridPrivateSettingsProviderProps = {
    children: React.ReactNode
} & Partial<GridPrivateSettingsContextType>

export const GridPrivateSettingsProvider = ({
    children,
    hideHeaders = false,
    initialFocusMode = 'cell',
    loopHorizontally = false,
    spreadsheet = false,
    onRangeSelectionChange,
    rangeSelection,
    onRangeCopy,
    onBulkCellChange,
    disableHorizontalScroll = false,
    onScrollbarVisibilityChange,
}: GridPrivateSettingsProviderProps) => {
    const value = React.useMemo(
        () => ({
            hideHeaders,
            initialFocusMode,
            loopHorizontally,
            spreadsheet,
            rangeSelection,
            onRangeSelectionChange,
            onRangeCopy,
            onBulkCellChange,
            disableHorizontalScroll,
            onScrollbarVisibilityChange,
        }),
        [
            hideHeaders,
            initialFocusMode,
            loopHorizontally,
            spreadsheet,
            rangeSelection,
            onRangeSelectionChange,
            onRangeCopy,
            onBulkCellChange,
            disableHorizontalScroll,
            onScrollbarVisibilityChange,
        ]
    )
    return (
        <GridPrivateSettingsContext.Provider value={value}>
            {children}
        </GridPrivateSettingsContext.Provider>
    )
}
