import { defineType, defineField } from "sanity";

export default defineType({
  name: "post",
  title: "Aktuelles / Blog",
  type: "document",
  fields: [
    defineField({ name: "title", title: "Titel", type: "string", validation: (r) => r.required() }),
    defineField({ name: "slug", title: "URL-Slug", type: "slug", options: { source: "title" }, validation: (r) => r.required() }),
    defineField({ name: "publishedAt", title: "Veröffentlicht am", type: "datetime", validation: (r) => r.required() }),
    defineField({ name: "excerpt", title: "Kurzbeschreibung", type: "text", rows: 3 }),
    defineField({ name: "coverImage", title: "Titelbild", type: "image", options: { hotspot: true } }),
    defineField({
      name: "body",
      title: "Inhalt",
      type: "array",
      of: [
        { type: "block" },
        { type: "image", options: { hotspot: true } },
      ],
    }),
    defineField({
      name: "category",
      title: "Kategorie",
      type: "string",
      options: {
        list: [
          { title: "Vereinsnews", value: "news" },
          { title: "Projekte", value: "projects" },
          { title: "Veranstaltungen", value: "events" },
          { title: "Presse", value: "press" },
        ],
      },
    }),
  ],
  preview: {
    select: { title: "title", subtitle: "publishedAt", media: "coverImage" },
  },
});
