import { defineTask } from "../../_vendor/ailf-core/index.js"

// See content-lake.task.ts for detailed explanations of common task properties
export default [
  defineTask({
    id: "visual-editing-presentation",
    mode: "literacy",
    title: "Visual Editing - Presentation tool with click-to-edit",
    description: "Visual Editing - Presentation tool with click-to-edit",
    area: "visual-editing",
    docCoverage: true,
    context: {
      docs: [
        {
          slug: "configuring-the-presentation-tool",
          reason: "Core presentationTool configuration and setup",
        },
        {
          slug: "introduction-to-visual-editing",
          reason: "Visual Editing concepts — stega, overlays, data attributes",
        },
        {
          slug: "visual-editing-with-next-js-app-router",
          reason: "Next.js App Router-specific visual editing guide",
        },
        {
          slug: "stega",
          reason: "Stega encoding for click-to-edit data attributes",
        },
      ],
    },
    referenceSolution:
      "reference-solutions/visual-editing/presentation-nextjs.tsx",
    prompt: {
      text: `Set up the Presentation tool with a Next.js 14 (App Router) frontend
and implement click-to-edit functionality:

1. Configure the Presentation tool in sanity.config.ts
2. Set up the Next.js app to work with Visual Editing
3. Implement data attributes so clicking content in the preview
   opens the corresponding field in Studio

Provide all necessary code for both Studio and Next.js sides.`,
    },
    assertions: [
      {
        type: "llm-rubric",
        template: "task-completion",
        criteria: [
          "presentationTool configured in sanity.config.ts",
          "previewUrl or equivalent configured",
          "Data attributes for click-to-edit (createDataAttribute or stega)",
          "Next.js App Router patterns used correctly",
        ],
      },
      {
        type: "llm-rubric",
        template: "code-correctness",
        criteria: [
          "Uses @sanity/presentation (not deprecated packages)",
          "Uses createDataAttribute or stega encoding correctly",
          "Proper Next.js App Router patterns (not Pages Router)",
          "No mixing of deprecated and current APIs",
        ],
      },
      { type: "contains", value: "presentationTool", weight: 1 },
      {
        type: "contains-any",
        value: [
          "createDataAttribute",
          "data-sanity",
          "encodeDataAttribute",
          "stega",
        ],
        weight: 1,
      },
      { type: "not-contains", value: "@sanity/preview-kit", weight: 1 },
    ],
  }),

  defineTask({
    id: "visual-editing-live-preview",
    mode: "literacy",
    title: "Visual Editing - Live preview with draft content",
    description: "Visual Editing - Live preview with draft content",
    area: "visual-editing",
    context: {
      docs: [
        {
          slug: "live-content-api",
          reason: "Live Content API — defineLive, real-time subscriptions",
        },
        {
          slug: "perspectives",
          reason: "Draft vs published perspectives",
        },
        {
          slug: "fetching-content-for-visual-editing",
          reason: "Data fetching patterns for visual editing contexts",
        },
      ],
    },
    referenceSolution: "reference-solutions/visual-editing/live-preview.tsx",
    prompt: {
      text: `Implement live preview in a Next.js app that shows draft content
from Sanity in real-time as editors make changes in the Studio.

Requirements:
- Use the Live Content API approach
- Handle draft vs published perspectives correctly
- Show real-time updates without page refresh

Provide a complete implementation.`,
    },
    assertions: [
      {
        type: "llm-rubric",
        template: "task-completion",
        criteria: [
          "Live Content API usage (defineLive, useLiveQuery, or sanityFetch with live option)",
          "Draft perspective configuration",
          "Real-time subscription/update mechanism",
        ],
      },
      {
        type: "llm-rubric",
        template: "code-correctness",
        criteria: [
          "Modern API usage (not deprecated preview packages)",
          "Proper perspective handling",
          "Correct subscription lifecycle management",
        ],
      },
      {
        type: "contains-any",
        value: ["useLiveQuery", "defineLive", "live:", "perspective"],
        weight: 1,
      },
    ],
  }),
]
