import { create } from "zustand" import { generateId } from "@/lib/id" import { mockPosts } from "@/lib/mock" import type { Post, User, UserRole } from "@/lib/types" interface CreatePostInput { author: User authorRole: UserRole title: string content: string images: string[] tags: string[] linkedOrderId?: string quotedPostId?: string } interface PostState { posts: Post[] createPost: (input: CreatePostInput) => Post } export const usePostStore = create((set) => ({ posts: mockPosts, createPost: (input) => { const post: Post = { id: generateId("post"), author: input.author, authorRole: input.authorRole, title: input.title.trim(), content: input.content.trim(), images: input.images, tags: input.tags, linkedOrderId: input.linkedOrderId, quotedPostId: input.quotedPostId, likeCount: 0, commentCount: 0, liked: false, pinned: false, createdAt: new Date().toISOString(), } set((state) => ({ posts: [post, ...state.posts], })) return post }, }))