'use client'

import { type ReactNode, useMemo, useState } from 'react'

import { IFileInfo } from '@/types'

import {
	CreateComponentContext,
	type CreateComponentContextProps
} from '@/contexts'

type CreateComponentProviderProps = {
	children: ReactNode
}

export function CreateComponentProvider({
	children
}: CreateComponentProviderProps) {
	const [name, setName] = useState<string>('')
	//
	const [fileInfo, setFileInfo] = useState<IFileInfo | null>(null)
	//
	const [componentPath, setComponentPath] = useState('')

	const contextValue = useMemo<CreateComponentContextProps>(
		() => ({
			name,
			setName,
			//
			fileInfo,
			setFileInfo,
			//
			componentPath,
			setComponentPath
		}),
		[
			name,
			setName,
			//
			fileInfo,
			setFileInfo,
			//
			componentPath,
			setComponentPath
		]
	)

	return (
		<CreateComponentContext.Provider value={contextValue}>
			{children}
		</CreateComponentContext.Provider>
	)
}
