import { addDays, addMinutes, formatISO, setHours, setMinutes, subHours } from "date-fns";

import type { AppState } from "./types";

const now = new Date();
const todayMorning = setMinutes(setHours(now, 9), 30);
const reviewStart = setMinutes(setHours(now, 13), 0);
const reviewEnd = setMinutes(setHours(now, 14), 0);

export function createSeedState(): AppState {
  return {
    theme: "light",
    session: {
      id: "user-1",
      name: "Taylor",
      email: "taylor@productier.app"
    },
    workspaces: [
      {
        id: "workspace-1",
        slug: "personal",
        name: "Personal HQ",
        role: "owner",
        createdAt: formatISO(subHours(now, 72))
      }
    ],
    members: [
      {
        id: "member-1",
        workspaceSlug: "personal",
        name: "Taylor",
        email: "taylor@productier.app",
        role: "owner",
        status: "active"
      },
      {
        id: "member-2",
        workspaceSlug: "personal",
        name: "Alex",
        email: "alex@productier.app",
        role: "member",
        status: "active"
      }
    ],
    invites: [
      {
        id: "invite-1",
        workspaceSlug: "personal",
        email: "jamie@productier.app",
        role: "member",
        token: "invite-jamie",
        createdAt: formatISO(subHours(now, 12)),
        status: "pending"
      }
    ],
    boardGroups: [
      { id: "group-inbox", workspaceSlug: "personal", name: "Inbox", color: "slate", order: 0 },
      { id: "group-doing", workspaceSlug: "personal", name: "Doing", color: "rose", order: 1 },
      { id: "group-review", workspaceSlug: "personal", name: "Review", color: "amber", order: 2 },
      { id: "group-done", workspaceSlug: "personal", name: "Done", color: "emerald", order: 3 }
    ],
    labels: [
      { id: "label-launch", workspaceSlug: "personal", name: "Launch", color: "rose" },
      { id: "label-ui", workspaceSlug: "personal", name: "UI", color: "amber" },
      { id: "label-deep", workspaceSlug: "personal", name: "Deep Work", color: "emerald" },
      { id: "label-admin", workspaceSlug: "personal", name: "Admin", color: "blue" }
    ],
    tasks: [
      {
        id: "task-foundation",
        workspaceSlug: "personal",
        boardGroupId: "group-doing",
        title: "Finalize Productier foundation",
        description:
          "Align the web shell, board, and calendar so the app feels calm, premium, and mobile-ready.",
        status: "in_progress",
        color: "rose",
        dueAt: formatISO(addDays(now, 1)),
        scheduledStart: formatISO(todayMorning),
        scheduledEnd: formatISO(addMinutes(todayMorning, 90)),
        assigneeId: "member-1",
        labelIds: ["label-launch", "label-ui"],
        attachments: [],
        comments: [
          {
            id: "comment-1",
            taskId: "task-foundation",
            author: "Alex",
            content: "Keep the calendar dense, but not cramped.",
            createdAt: formatISO(subHours(now, 5))
          }
        ],
        recurrenceRule: "",
        archived: false,
        createdAt: formatISO(subHours(now, 24)),
        updatedAt: formatISO(subHours(now, 2))
      },
      {
        id: "task-copy",
        workspaceSlug: "personal",
        boardGroupId: "group-inbox",
        title: "Refine onboarding copy",
        description: "Make the empty states feel useful without becoming noisy.",
        status: "todo",
        color: "slate",
        assigneeId: "member-2",
        labelIds: ["label-admin"],
        attachments: [],
        comments: [],
        recurrenceRule: "",
        archived: false,
        createdAt: formatISO(subHours(now, 12)),
        updatedAt: formatISO(subHours(now, 12))
      },
      {
        id: "task-sync",
        workspaceSlug: "personal",
        boardGroupId: "group-review",
        title: "Review offline queue behavior",
        description: "Preserve local drafts when queued edits would conflict after reconnect.",
        status: "todo",
        color: "amber",
        labelIds: ["label-launch"],
        attachments: [],
        comments: [],
        recurrenceRule: "",
        archived: false,
        createdAt: formatISO(subHours(now, 8)),
        updatedAt: formatISO(subHours(now, 4))
      }
    ],
    events: [
      {
        id: "event-review",
        workspaceSlug: "personal",
        title: "Design review",
        description: "Tighten spacing rhythm and modal hierarchy.",
        startsAt: formatISO(reviewStart),
        endsAt: formatISO(reviewEnd),
        color: "amber",
        linkedTaskId: "task-foundation",
        attachments: []
      },
      {
        id: "event-checkin",
        workspaceSlug: "personal",
        title: "Weekly check-in",
        description: "Review priorities for the next sprint.",
        startsAt: formatISO(addDays(reviewStart, 2)),
        endsAt: formatISO(addDays(reviewEnd, 2)),
        color: "blue",
        attachments: []
      }
    ],
    notes: [
      {
        id: "note-direction",
        workspaceSlug: "personal",
        title: "Calm UI direction",
        content:
          "# Design guardrails\n\n- Keep the board readable on small screens.\n- Use one accent hue at a time.\n- Treat the calendar as a planning surface, not a spreadsheet.",
        updatedAt: formatISO(subHours(now, 3))
      },
      {
        id: "note-roadmap",
        workspaceSlug: "personal",
        title: "Phase outline",
        content:
          "## Phase 1\n\nFoundation, auth shell, board/calendar basics.\n\n## Phase 2\n\nNotes, focus, attachments, offline queue.",
        updatedAt: formatISO(subHours(now, 20))
      }
    ],
    focusSessions: [
      {
        id: "focus-complete",
        workspaceSlug: "personal",
        taskId: "task-foundation",
        mode: "focus",
        startedAt: formatISO(subHours(now, 2)),
        completedAt: formatISO(subHours(now, 1.5)),
        pausedTotalSeconds: 0,
        durationSeconds: 1500
      }
    ],
    activities: [
      {
        id: "activity-1",
        workspaceSlug: "personal",
        title: "Board updated",
        detail: "Task moved into Review.",
        createdAt: formatISO(subHours(now, 4))
      },
      {
        id: "activity-2",
        workspaceSlug: "personal",
        title: "Invite created",
        detail: "Jamie was invited to Personal HQ.",
        createdAt: formatISO(subHours(now, 10))
      }
    ],
    offlineQueue: [],
    // CRM
    contacts: [
      {
        id: "contact-1",
        workspaceSlug: "personal",
        firstName: "Sarah",
        lastName: "Chen",
        email: "sarah@example.com",
        phone: "+1-555-0100",
        title: "Product Manager",
        notes: "Main point of contact for the integration project",
        avatarUrl: "",
        createdAt: formatISO(subHours(now, 48)),
        updatedAt: formatISO(subHours(now, 48))
      },
      {
        id: "contact-2",
        workspaceSlug: "personal",
        firstName: "Marcus",
        lastName: "Rivera",
        email: "marcus@example.com",
        phone: "+1-555-0101",
        title: "Engineering Lead",
        notes: "",
        avatarUrl: "",
        createdAt: formatISO(subHours(now, 24)),
        updatedAt: formatISO(subHours(now, 24))
      }
    ],
    companies: [
      {
        id: "company-1",
        workspaceSlug: "personal",
        name: "Acme Corp",
        domain: "acme.com",
        website: "https://acme.com",
        industry: "Technology",
        size: "51-200",
        notes: "Enterprise customer, priority support",
        logoUrl: "",
        createdAt: formatISO(subHours(now, 72)),
        updatedAt: formatISO(subHours(now, 72))
      }
    ],
    inboxItems: [],
    timeEntries: [],
    savedViews: [],
    // Integrations
    integrations: [],
    webhooks: [],
    notifications: []
  };
}
