import { createMachine } from 'xstate';

export const formMachine = createMachine(
    {
        id: 'validation',
        initial: 'notValidated',
        context: {
            isValidated: false
        },
        states: {
            notValidated: {
                on: {
                    VALIDATE: {
                        target: 'isValidated',
                        actions: 'setValidated'
                    }
                }
            },
            isValidated: {
                on: {
                    INVALIDATE: {
                        target: 'notValidated',
                        actions: 'setNotValidated'
                    }
                }
            }
        }
    },
    {
        actions: {
            setValidated: (context) => (context.isValidated = true),
            setNotValidated: (context) => (context.isValidated = false)
        }
    }
);