// slices/ReelIdSlice.ts
import { createSlice, PayloadAction } from "@reduxjs/toolkit";

interface SelectedPostIdState {
  id: string | null;
  share_count: string;
  post_type: string;
}

const initialState: SelectedPostIdState = {
  id: null,
  share_count: "0",
  post_type:""
};

const PostIdSlice = createSlice({
  name: "PostId",
  initialState,
  reducers: {
    setPostId: (state, action: PayloadAction<{ id: string; share_count: number; post_type: string }>) => {
      state.id = action.payload.id;
      state.share_count = String(action.payload.share_count);
      state.post_type = action.payload.post_type
    },
    clearPostId: (state) => {
      state.id = null;
      state.share_count = "0";
    },
    incrementShareCount: (state) => {
      const currentCount = parseInt(state.share_count || "0", 10);
      state.share_count = String(currentCount + 1);
    },
    setShareCount: (state, action: PayloadAction<number>) => {
      state.share_count = String(action.payload);
    },
  },
});

export const {
  setPostId,
  clearPostId,
  incrementShareCount,
  setShareCount,
} = PostIdSlice.actions;

export default PostIdSlice.reducer;
