import {createSlice} from '@reduxjs/toolkit';
import {Button, useToast, Box, Center, NativeBaseProvider} from 'native-base';
import React from 'react';

export const authSlice = createSlice({
  name: 'authentication',
  initialState: {
    loading: false,
    isLogin: true,
    user: {},
  },
  reducers: {
    login(state, action) {
      // state.loading = true;
      const {email, password} = action.payload.data;

      if (email.length > 1) {
        if (email === 'ameen' && password === '123') {
          state.isLogin = true;
        } else {
          console.log('fail email test');
          state.loading = false;
          state.isLogin = false;
          action.payload.showToastWithGravityAndOffset(
            'Invalid Email or Password',
          );
        }
      } else {
        action.payload.showToastWithGravityAndOffset(
          'Enter email and pasword to continue',
        );
        state.loading = false;
      }
    },
    logout(state, action) {
      console.log("Logout")
      state.isLogin = false;
    },
  },
});
// each case under reducers becomes an action
export const {login, logout} = authSlice.actions;
export default authSlice.reducer;
