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 getPrivacy_Policy = createAsyncThunk(
    'home/add-privacy_policy',
    async (_, { rejectWithValue }) => {
        try {
            const privacypolicyData = await GET(API.GET_Privacy_Policy);
            return privacypolicyData;

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

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

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

export default Slice.reducer;


