"use client"

import {createContext, ReactNode, FC, useState, Dispatch, SetStateAction} from "react";
import {Job} from "../type";

type JobsContextPayload = {
	data: Job[]
	filter?: string
	setFilter: Dispatch<SetStateAction<string | undefined>>
} | undefined

export const JobsContext = createContext<JobsContextPayload>(undefined);

type JobsContextProviderProps = {
	jobs: Job[]
	children: ReactNode[]
}

export const JobsProvider: FC<JobsContextProviderProps> = ({children, jobs: data}) => {
	const [filter, setFilter] = useState<string>()

	return (
		<JobsContext value={{data, filter, setFilter}}>{children}</JobsContext>
	)
}