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

const rec: RecordSpec = {
  name: "Tasks", table: "tasks", display: "title", required: [],
  fields: { title: { type: "text" }, done: { type: "boolean" } },
};

const rows: DataRow[] = [
  { id: "1", title: "Set up database schema", done: 1 },
  { id: "2", title: "Write API endpoints", done: 1 },
  { id: "3", title: "Build frontend components", done: 0 },
  { id: "4", title: "Add unit tests", done: 0 },
  { id: "5", title: "Deploy to production", done: 0 },
];

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

export const Default: Story = {
  render: () => <ChecklistView rows={rows} rec={rec} titleField="title" checkedField="done" table="tasks" onViewDetail={() => {}} />,
};
