import { defineType, defineField } from "sanity";

export default defineType({
  name: "project",
  title: "Projekte",
  type: "document",
  fields: [
    defineField({ name: "title", title: "Projektname", type: "string", validation: (r) => r.required() }),
    defineField({ name: "slug", title: "URL-Slug", type: "slug", options: { source: "title" }, validation: (r) => r.required() }),
    defineField({ name: "date", title: "Zeitraum", type: "string", description: 'z.B. "Sommer 2024" oder "März–Mai 2024"' }),
    defineField({ name: "summary", title: "Kurzbeschreibung", type: "text", rows: 3, validation: (r) => r.required() }),
    defineField({
      name: "body",
      title: "Ausführliche Beschreibung",
      type: "array",
      of: [{ type: "block" }, { type: "image", options: { hotspot: true } }],
    }),
    defineField({ name: "image", title: "Hauptbild", type: "image", options: { hotspot: true } }),
    defineField({ name: "targetGroup", title: "Für wen", type: "string", description: 'z.B. "Alle Kinder" oder "Gruppe Schmetterlinge"' }),
    defineField({ name: "featured", title: "Auf Startseite hervorheben?", type: "boolean", initialValue: false }),
    defineField({
      name: "status",
      title: "Status",
      type: "string",
      options: {
        list: [
          { title: "Geplant", value: "planned" },
          { title: "Laufend", value: "active" },
          { title: "Abgeschlossen", value: "done" },
        ],
      },
      initialValue: "done",
    }),
  ],
  preview: {
    select: { title: "title", subtitle: "date", media: "image" },
  },
});
