import React from 'react';
import {createContext, ReactNode, useContext, useState} from 'react';

interface IValueProps {
  agree?: boolean;
}

export interface ITncProps {
  value: IValueProps;
  setValue: (data: IValueProps) => void;
}

const contextDefaultValues: ITncProps = {
  value: {agree: false},
  setValue: (data: IValueProps) => data,
};

const TncContext = createContext<ITncProps>(contextDefaultValues);

export const TncProvider = ({children}: {children: ReactNode}) => {
  const [value, setValue] = useState(contextDefaultValues.value);

  return (
    <TncContext.Provider value={{value, setValue}}>
      {children}
    </TncContext.Provider>
  );
};

export default () => useContext(TncContext);
