import { create } from 'zustand';

export type ApprovalItem = {
  id: string;
  title: string;
  summary: string;
  status: 'pending' | 'approved' | 'rejected';
};

export type InboxState = {
  approvals: ApprovalItem[];
  approve: (id: string) => void;
  reject: (id: string) => void;
};

export const useInboxStore = create<InboxState>((set) => ({
  approvals: [
    {
      id: 'approval-1',
      title: 'Apply note merge suggestion',
      summary: 'Agent proposed merging two near-duplicate product planning notes.',
      status: 'pending',
    },
    {
      id: 'approval-2',
      title: 'Create linked task from note',
      summary: 'Agent extracted a task from a meeting note and queued it for approval.',
      status: 'pending',
    },
  ],
  approve(id: string) {
    set((state) => ({
      approvals: state.approvals.map((item) =>
        item.id === id ? { ...item, status: 'approved' } : item,
      ),
    }));
  },
  reject(id: string) {
    set((state) => ({
      approvals: state.approvals.map((item) =>
        item.id === id ? { ...item, status: 'rejected' } : item,
      ),
    }));
  },
}));
