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


// Thunk for getting Add banners
export const getReturn_Policy = createAsyncThunk(
    'home/add-return_policy',
    async (_, { rejectWithValue }) => {
        try {
            const returnpolicyData = await GET(API.GET_Return_Policy);
            return returnpolicyData;

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

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

            .addCase(getReturn_Policy.pending, (state) => {
                state.status = 'loading';
                
            })
            .addCase(getReturn_Policy.fulfilled, (state, action) => {
                state.status = 'succeeded';
                state.addReturnPolicy = action.payload?.data || [];
                console.log('State after fulfilled', state);
            })
            .addCase(getReturn_Policy.rejected, (state, action) => {
                state.status = 'failed';
                state.error = action.payload;
                console.log('State after rejected', state);
            })
            
            
    },
});

export default Slice.reducer;


