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

// Thunk for getting Add banners
export const getSocialmedia = createAsyncThunk(
  "common/master/add-socialmedia",
  async (_, { rejectWithValue }) => {
    try {
      const socialmediaData = await GET(API.GET_SOCIAL_MEDIA);
      return socialmediaData;
    } catch (error) {
      return rejectWithValue(error.message);
    }
  },
);

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

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

export default Slice.reducer;
