import { defineType, defineField } from "sanity";

export default defineType({
  name: "teamMember",
  title: "Vorstandsmitglieder",
  type: "document",
  fields: [
    defineField({ name: "name", title: "Name", type: "string", validation: (r) => r.required() }),
    defineField({
      name: "role",
      title: "Funktion",
      type: "string",
      options: {
        list: [
          { title: "Vorsitzende/r", value: "chair" },
          { title: "Stellvertretung", value: "deputy" },
          { title: "Kassenwart/in", value: "treasurer" },
          { title: "Beisitz", value: "board" },
        ],
      },
      validation: (r) => r.required(),
    }),
    defineField({ name: "bio", title: "Kurz-Bio", type: "text", rows: 2 }),
    defineField({ name: "photo", title: "Foto", type: "image", options: { hotspot: true } }),
    defineField({ name: "order", title: "Reihenfolge", type: "number", initialValue: 99 }),
  ],
  orderings: [{ title: "Reihenfolge", name: "orderAsc", by: [{ field: "order", direction: "asc" }] }],
  preview: {
    select: { title: "name", subtitle: "role", media: "photo" },
  },
});
