import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { GET } from "../../utils/api";
import { API } from "../../endpoints/common_endpoints";


// Thunk for getting Add banners
export const getHelp = createAsyncThunk(
    'website/home/add-help',
    async (_, { rejectWithValue }) => {
        try {
            const helpData = await GET(API.GET_HELP);
            return helpData;

        } catch (error) {
            return rejectWithValue(error.message);
        }
    }
);


// Create the slice
const Slice = createSlice({
    name: "help",
    initialState: {
        name: '',
        image: '',
        description: '',
        addHelp: [],
        error: null,
        status: 'idle',
    },
    reducers: {},
    extraReducers: (builder) => {
        builder

            .addCase(getHelp.pending, (state) => {
                state.status = 'loading';
               
            })
            .addCase(getHelp.fulfilled, (state, action) => {
                state.status = 'succeeded';
                state.addHelp = action.payload?.data || [];
              
            })
            .addCase(getHelp.rejected, (state, action) => {
                state.status = 'failed';
                state.error = action.payload;
               
            });

    },
});

export default Slice.reducer;


