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 getTerms_and_Conditions = createAsyncThunk(
    'home/add-return_policy',
    async (_, { rejectWithValue }) => {
        try {
            const termsconditionsData = await GET(API.GET_TERM_CONDITION);
            return termsconditionsData;

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

// Create the slice
const Slice = createSlice({
    name: "termsconditions",
    initialState: {
        content: '',
        error: null,
        status: 'idle',
    },
    reducers: {},
    extraReducers: (builder) => {
        builder

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


    },
});

export default Slice.reducer;


