import type { Meta, StoryObj } from "@storybook/preact";
import { CalendarView } from "./CalendarView";
import type { RecordSpec, DataRow } from "@/types/spec";

const rec: RecordSpec = {
  name: "Events", table: "events", display: "title", required: [],
  fields: {
    title: { type: "text" },
    date: { type: "date" },
    type: { type: "choice", choices: ["meeting", "call", "deadline"], colors: { meeting: "blue", call: "green", deadline: "red" } },
  },
};

const today = new Date();
const d = (offset: number) => {
  const dt = new Date(today); dt.setDate(dt.getDate() + offset);
  return dt.toISOString().slice(0, 10);
};

const rows: DataRow[] = [
  { id: "1", title: "Team standup", date: d(0), type: "meeting" },
  { id: "2", title: "Client call", date: d(1), type: "call" },
  { id: "3", title: "Sprint deadline", date: d(3), type: "deadline" },
  { id: "4", title: "Design review", date: d(0), type: "meeting" },
  { id: "5", title: "1:1 with manager", date: d(5), type: "meeting" },
  { id: "6", title: "Deploy v2.0", date: d(7), type: "deadline" },
];

const meta: Meta<typeof CalendarView> = { title: "Views/CalendarView", component: CalendarView, parameters: { layout: "padded" } };
export default meta;
type Story = StoryObj<typeof CalendarView>;

export const Default: Story = {
  render: () => <CalendarView rows={rows} rec={rec} dateField="date" titleField="title" badgeField="type" onViewDetail={() => {}} table="events" />,
};

export const Empty: Story = {
  render: () => <CalendarView rows={[]} rec={rec} dateField="date" titleField="title" onViewDetail={() => {}} table="events" />,
};
