import {defineArrayMember, defineField, defineType} from "sanity";

export const homePage = defineType({
  name: "homePage",
  title: "Page d'accueil",
  type: "document",
  groups: [
    {name: "hero", title: "Hero", default: true},
    {name: "carousel", title: "Carousel"},
    {name: "reassurance", title: "Réassurance"},
  ],
  fields: [
    defineField({name: "heroTitle", type: "string", group: "hero", validation: (r) => r.required()}),
    defineField({name: "heroSubtitle", type: "text", group: "hero"}),
    defineField({name: "heroImage", type: "image", group: "hero", options: {hotspot: true}}),
    defineField({
      name: "featuredCollectionHandle",
      title: "Featured Collection Handle",
      type: "string",
      group: "carousel",
    }),
    defineField({
      name: "featuredProducts",
      title: "Produits du carousel",
      type: "array",
      group: "carousel",
      description: "Selection manuelle des produits pour le carousel.",
      of: [
        defineArrayMember({
          type: "reference",
          to: [{type: "product"}],
          options: {
            filter: 'status == "publish" && defined(slug.current) && coalesce(isActive, true) == true',
          },
        }),
      ],
    }),
    defineField({
      name: "reassurance",
      title: "Réassurance",
      type: "reassuranceSection",
      group: "reassurance",
      description: "Éléments de confiance pour rassurer les clients",
    }),
  ],
});

