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

function formatSupplementPrice(priceCents?: number | null) {
  if (typeof priceCents !== "number" || !Number.isFinite(priceCents) || priceCents <= 0) {
    return "";
  }

  const euros = (Math.round(priceCents) / 100).toFixed(2).replace(".", ",");
  return ` (+${euros} EUR)`;
}

function normalizeFieldKey(value: unknown) {
  return typeof value === "string"
    ? value
        .normalize("NFD")
        .replace(/[\u0300-\u036f]/g, "")
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, "-")
        .replace(/^-+|-+$/g, "")
    : "";
}

function isGiftCompartmentField(parent: {key?: unknown; label?: unknown}) {
  return normalizeFieldKey(parent.key) === "compartiment-arriere-cadeau" || normalizeFieldKey(parent.label) === "compartiment-arriere-cadeau";
}

const EVENT_POPUP_CATEGORY_OPTIONS = [
  {title: "Anniversaire", value: "birthday"},
  {title: "Baptême", value: "baptism"},
  {title: "Cadeau personnalisé", value: "gift"},
  {title: "Remerciement", value: "teacher"},
  {title: "Mariage", value: "wedding"},
  {title: "Pack complet", value: "complete-pack"},
];

export const product = defineType({
  name: "product",
  title: "Product",
  type: "document",
  groups: [
    {name: "general", title: "General", default: true},
    {name: "variations", title: "Variations"},
    {name: "themes", title: "Themes"},
    {name: "personalization", title: "Personnalisation"},
  ],
  fields: [
    defineField({name: "title", type: "string", group: "general", validation: (r) => r.required()}),
    defineField({
      name: "slug",
      type: "slug",
      group: "general",
      options: {source: "title"},
      validation: (r) => r.required(),
    }),
    defineField({name: "wooId", title: "WooCommerce ID", type: "number", group: "general"}),
    defineField({name: "status", type: "string", group: "general", initialValue: "publish"}),
    defineField({
      name: "isActive",
      title: "Active",
      type: "boolean",
      group: "general",
      initialValue: true,
      description: "Affiche ou masque cette fiche produit sur la boutique.",
    }),
    defineField({name: "productType", type: "string", group: "general"}),
    defineField({
      name: "displayBadge",
      title: "Badge affiche",
      type: "string",
      group: "general",
      description: "Texte court affiche en haut a gauche de la carte produit et de la fiche produit.",
      validation: (r) => r.max(32),
    }),
    defineField({name: "shortDescription", type: "text", group: "general"}),
    defineField({
      name: "careText",
      title: "Care text",
      type: "text",
      group: "general",
      description: "Texte court affiche sous l'image sur la fiche produit.",
    }),
    defineField({
      name: "isCustomizable",
      title: "Produit personnalisable",
      type: "boolean",
      group: "personalization",
      initialValue: true,
      description: "Active l'affichage du bloc de personnalisation sur la fiche produit.",
    }),
    defineField({
      name: "showPaperFinish",
      title: "Afficher l'effet du papier",
      type: "boolean",
      group: "personalization",
      initialValue: true,
      description: "Affiche le choix d'effet papier existant sur la fiche produit.",
    }),
    defineField({
      name: "paperFinishRequired",
      title: "Effet du papier requis",
      type: "boolean",
      group: "personalization",
      hidden: ({document}) => document?.showPaperFinish !== true,
      initialValue: false,
      description: "Force la selection d'un effet du papier avant l'ajout au panier.",
    }),
    defineField({
      name: "showThemes",
      title: "Afficher les themes",
      type: "boolean",
      group: "themes",
      initialValue: false,
      description: "Active l'affichage du choix de theme sur cette fiche produit.",
    }),
    defineField({
      name: "themes",
      title: "Themes disponibles",
      type: "array",
      group: "themes",
      hidden: ({document}) => document?.showThemes !== true,
      description: "Selectionnez les themes a proposer pour ce produit.",
      of: [defineArrayMember({type: "reference", to: [{type: "theme"}]})],
    }),
    defineField({
      name: "themeOptions",
      title: "Theme options legacy",
      type: "array",
      hidden: true,
      readOnly: true,
      of: [defineArrayMember({type: "string"})],
    }),
    defineField({
      name: "personalizationTextField",
      title: "Texte libre de personnalisation",
      type: "object",
      group: "personalization",
      description: "Configure le grand champ texte libre affiche sur la fiche produit.",
      fields: [
        defineField({
          name: "isEnabled",
          title: "Afficher le champ",
          type: "boolean",
          initialValue: true,
        }),
        defineField({
          name: "label",
          title: "Libelle",
          type: "string",
          description: "Titre affiche au-dessus du champ.",
        }),
        defineField({
          name: "showLabel",
          title: "Afficher le libelle",
          type: "boolean",
          initialValue: false,
          description: "Masquez le titre si vous souhaitez n'afficher que le placeholder.",
        }),
        defineField({
          name: "helperText",
          title: "Texte d'aide",
          type: "string",
          description: "Petit texte sous le libelle pour guider la saisie.",
        }),
        defineField({
          name: "placeholder",
          title: "Placeholder",
          type: "string",
        }),
        defineField({
          name: "defaultValue",
          title: "Valeur par defaut",
          type: "string",
        }),
        defineField({
          name: "maxLength",
          title: "Longueur maximale",
          type: "number",
        }),
        defineField({
          name: "required",
          title: "Champ requis",
          type: "boolean",
          initialValue: true,
        }),
      ],
      preview: {
        select: {
          isEnabled: "isEnabled",
          label: "label",
          showLabel: "showLabel",
          placeholder: "placeholder",
        },
        prepare: ({isEnabled, label, showLabel, placeholder}) => ({
          title: label || "Texte libre de personnalisation",
          subtitle: [
            isEnabled === false ? "Masque" : "Affiche",
            showLabel === false ? "Libelle masque" : "Libelle visible",
            placeholder || "",
          ]
            .filter(Boolean)
            .join(" • "),
        }),
      },
    }),
    defineField({
      name: "personalizationFields",
      title: "Champs de personnalisation",
      type: "array",
      group: "personalization",
      description: "Champs personnalises affiches sur la fiche produit, en plus du texte libre.",
      of: [
        defineArrayMember({
          type: "object",
          fields: [
            defineField({
              name: "label",
              title: "Libelle",
              type: "string",
              validation: (r) => r.required(),
            }),
            defineField({
              name: "key",
              title: "Cle technique",
              type: "string",
              description: "Optionnel. Laissez vide pour la generer automatiquement depuis le libelle.",
              validation: (r) =>
                r.custom((value) => {
                  if (!value) return true;
                  return /^[a-z0-9-]+$/.test(value.trim())
                    ? true
                    : "Utilisez uniquement des lettres minuscules, chiffres et tirets.";
                }),
            }),
            defineField({
              name: "inputType",
              title: "Type de champ",
              type: "string",
              initialValue: "choices",
              options: {
                list: [
                  { title: "Choix", value: "choices" },
                  { title: "Select", value: "select" },
                  { title: "Boutons radio", value: "radio" },
                  { title: "Texte court", value: "text" },
                  { title: "Texte long", value: "textarea" },
                  { title: "Email", value: "email" },
                  { title: "Telephone", value: "tel" },
                  { title: "Nombre", value: "number" },
                  { title: "Date", value: "date" },
                  { title: "Image", value: "image" },
                  { title: "Couleur", value: "color" },
                ],
                layout: "radio",
              },
              validation: (r) => r.required(),
            }),
            defineField({
              name: "useThemeOptions",
              title: "Utiliser la liste de themes",
              type: "boolean",
              hidden: ({parent}) => !["choices", "select", "radio"].includes(parent?.inputType || ""),
              initialValue: false,
              description: "Reprend automatiquement la liste definie dans l'onglet Themes.",
            }),
            defineField({
              name: "options",
              title: "Options",
              type: "array",
              hidden: ({parent}) =>
                !["choices", "select", "radio"].includes(parent?.inputType || "") || parent?.useThemeOptions === true,
              of: [
                defineArrayMember({
                  type: "object",
                  fields: [
                    defineField({
                      name: "label",
                      title: "Libelle",
                      type: "string",
                      validation: (r) => r.required(),
                    }),
                    defineField({
                      name: "priceCents",
                      title: "Prix supplementaire (centimes)",
                      type: "number",
                      initialValue: 0,
                      description: "Laissez a 0 pour une option sans surcout.",
                      validation: (r) => r.min(0),
                    }),
                  ],
                  preview: {
                    select: {
                      label: "label",
                      priceCents: "priceCents",
                    },
                    prepare: ({label, priceCents}) => ({
                      title: `${label || "Option"}${formatSupplementPrice(priceCents)}`,
                      subtitle:
                        typeof priceCents === "number" && priceCents > 0
                          ? `Supplément: ${priceCents} centime(s)`
                          : "Sans supplément",
                    }),
                  },
                }),
              ],
              validation: (r) =>
                r.custom((value, context) => {
                  const parent = (context.parent || {}) as {inputType?: string; useThemeOptions?: boolean; key?: unknown; label?: unknown};
                  if (!["choices", "select", "radio"].includes(parent.inputType || "") || parent.useThemeOptions === true) return true;
                  if (isGiftCompartmentField(parent)) return true;
                  return (
                    Array.isArray(value) &&
                    value.some((item) => {
                      if (typeof item === "string") return item.trim().length > 0;
                      if (!item || typeof item !== "object" || Array.isArray(item)) return false;
                      const option = item as {label?: unknown};
                      return typeof option.label === "string" && option.label.trim().length > 0;
                    })
                  )
                    ? true
                    : "Ajoutez au moins une option.";
                }),
            }),
            defineField({
              name: "helperText",
              title: "Texte d'aide",
              type: "string",
              description: "Petit texte sous le libelle pour guider la saisie.",
            }),
            defineField({
              name: "helperImage",
              title: "Photo d'aide",
              type: "image",
              description: "Image affichee sur la photo principale pour montrer l'emplacement de ce champ.",
              options: {hotspot: false},
            }),
            defineField({
              name: "helperImageLabel",
              title: "Texte du lien photo d'aide",
              type: "string",
              hidden: ({parent}) => !parent?.helperImage,
              description: "Ex: Afficher l'emplacement de la fleur 1.",
            }),
            defineField({
              name: "showLabel",
              title: "Afficher le libelle",
              type: "boolean",
              initialValue: true,
              description: "Masquez le titre du champ sur la fiche produit si besoin.",
            }),
            defineField({
              name: "placeholder",
              title: "Placeholder",
              type: "string",
              hidden: ({ parent }) => ["choices", "select", "radio", "date", "image", "color"].includes(parent?.inputType || ""),
            }),
            defineField({
              name: "defaultValue",
              title: "Valeur par defaut",
              type: "string",
              description: "Preselection ou valeur initiale facultative.",
            }),
            defineField({
              name: "maxLength",
              title: "Longueur maximale",
              type: "number",
              hidden: ({ parent }) => !["text", "textarea", "email", "tel"].includes(parent?.inputType || ""),
            }),
            defineField({
              name: "required",
              title: "Champ requis",
              type: "boolean",
              initialValue: true,
            }),
          ],
          preview: {
            select: {
              title: "label",
              inputType: "inputType",
              options: "options",
              required: "required",
              showLabel: "showLabel",
            },
            prepare: ({ title, inputType, options, required, showLabel }) => ({
              title: title || "Champ",
              subtitle: [
                ["choices", "select", "radio"].includes(inputType) ? `${Array.isArray(options) ? options.length : 0} option(s)` : inputType || "Champ",
                required ? "Requis" : "Optionnel",
                showLabel === false ? "Libelle masque" : "Libelle visible",
              ].join(" • "),
            }),
          },
        }),
      ],
    }),
    defineField({
      name: "customThemeRequest",
      title: "Option je personnalise mon thème",
      type: "object",
      group: "personalization",
      description: "Ajoute une option qui ouvre une popup pour demander un thème sur mesure.",
      fields: [
        defineField({
          name: "isEnabled",
          title: "Activer l'option",
          type: "boolean",
          initialValue: true,
        }),
        defineField({
          name: "optionLabel",
          title: "Libelle du bouton",
          type: "string",
          initialValue: "Je personnalise mon thème",
        }),
        defineField({
          name: "modalTitle",
          title: "Titre de la popup",
          type: "string",
          initialValue: "Personnaliser mon thème",
        }),
        defineField({
          name: "helperText",
          title: "Texte d'aide court",
          type: "string",
        }),
        defineField({
          name: "modalDescription",
          title: "Description de la popup",
          type: "text",
          rows: 3,
        }),
      ],
      preview: {
        select: {
          isEnabled: "isEnabled",
          optionLabel: "optionLabel",
        },
        prepare: ({isEnabled, optionLabel}) => ({
          title: optionLabel || "Je personnalise mon thème",
          subtitle: isEnabled === false ? "Desactive" : "Active",
        }),
      },
    }),
    defineField({
      name: "eventPopupCategories",
      title: "Catégories pop-up événement",
      type: "array",
      group: "personalization",
      description:
        "Choisissez dans quelles catégories de la pop-up “Personnaliser l'expérience” ce produit doit apparaître. Laissez vide pour l'exclure.",
      of: [
        defineArrayMember({
          type: "string",
          options: {
            list: EVENT_POPUP_CATEGORY_OPTIONS,
          },
        }),
      ],
      validation: (r) => r.unique(),
    }),
    defineField({
      name: "descriptionRich",
      title: "Description",
      type: "richText",
      group: "general",
      description: "Utilisez l'editeur riche (gras, listes, titres, liens).",
    }),
    defineField({
      name: "description",
      title: "Description legacy (texte brut)",
      type: "text",
      group: "general",
      hidden: true,
    }),
    defineField({name: "priceCents", type: "number", group: "general"}),
    defineField({name: "regularPriceCents", type: "number", group: "general"}),
    defineField({name: "salePriceCents", type: "number", group: "general"}),
    defineField({name: "currencyCode", type: "string", group: "general", initialValue: "EUR"}),
    defineField({name: "stockStatus", type: "string", group: "general"}),
    defineField({name: "stockQuantity", type: "number", group: "general"}),
    defineField({
      name: "weight",
      title: "Poids (g)",
      type: "number",
      group: "general",
      description: "Poids du produit en grammes, utilise notamment pour la livraison.",
    }),
    defineField({
      name: "length",
      title: "Longueur (cm)",
      type: "number",
      group: "general",
      description: "Longueur du colis/produit en centimetres.",
    }),
    defineField({
      name: "width",
      title: "Largeur (cm)",
      type: "number",
      group: "general",
      description: "Largeur du colis/produit en centimetres.",
    }),
    defineField({
      name: "height",
      title: "Hauteur (cm)",
      type: "number",
      group: "general",
      description: "Hauteur du colis/produit en centimetres.",
    }),
    defineField({
      name: "mainImage",
      title: "Main image",
      type: "image",
      group: "general",
      options: {hotspot: true},
      fields: [defineField({name: "alt", title: "Alt text", type: "string"})],
      description: "Image principale du produit affichee sur le site.",
    }),
    defineField({
      name: "imageUrl",
      title: "Main image URL (legacy)",
      type: "url",
      group: "general",
      description: "Ancien champ conserve pour compatibilite. Preferez Main image.",
    }),
    defineField({
      name: "gallery",
      title: "Gallery",
      type: "array",
      group: "general",
      of: [
        defineArrayMember({
          type: "object",
          fields: [
            defineField({
              name: "image",
              title: "Image",
              type: "image",
              options: {hotspot: true},
            }),
            defineField({name: "url", title: "Image URL (legacy)", type: "url"}),
            defineField({name: "alt", title: "Alt text", type: "string"}),
          ],
          preview: {
            select: {title: "alt", subtitle: "url", media: "image"},
            prepare: ({title, subtitle, media}) => ({
              title: title || "Gallery image",
              subtitle,
              media,
            }),
          },
        }),
      ],
      description: "Photos supplementaires du produit, hors variations.",
    }),
    defineField({
      name: "categories",
      group: "general",
      type: "array",
      of: [defineArrayMember({type: "reference", to: [{type: "productCategory"}]})],
    }),
    defineField({name: "tags", type: "array", group: "general", of: [defineArrayMember({type: "string"})]}),
    defineField({
      name: "variationAxes",
      title: "Axes de variation",
      type: "array",
      group: "variations",
      description: "Structure V2 des variations. Definissez ici les dimensions vendues du produit (type, quantite, couleur, etc.).",
      of: [
        defineArrayMember({
          type: "object",
          fields: [
            defineField({
              name: "label",
              title: "Libelle",
              type: "string",
              validation: (r) => r.required(),
            }),
            defineField({
              name: "key",
              title: "Cle technique",
              type: "string",
              description: "Optionnel. Laissez vide pour la generer automatiquement depuis le libelle.",
              validation: (r) =>
                r.custom((value) => {
                  if (!value) return true;
                  return /^[a-z0-9-]+$/.test(value.trim())
                    ? true
                    : "Utilisez uniquement des lettres minuscules, chiffres et tirets.";
                }),
            }),
            defineField({
              name: "kind",
              title: "Nature de l'axe",
              type: "string",
              initialValue: "other",
              options: {
                list: [
                  {title: "Type de produit", value: "type"},
                  {title: "Quantite", value: "quantity"},
                  {title: "Theme", value: "theme"},
                  {title: "Effet", value: "finish"},
                  {title: "Couleur", value: "color"},
                  {title: "Autre", value: "other"},
                ],
                layout: "radio",
              },
              validation: (r) => r.required(),
            }),
            defineField({
              name: "values",
              title: "Valeurs",
              type: "array",
              of: [defineArrayMember({type: "string"})],
              validation: (r) =>
                r.custom((value) =>
                  Array.isArray(value) && value.some((item) => typeof item === "string" && item.trim())
                    ? true
                    : "Ajoutez au moins une valeur."
                ),
            }),
          ],
          preview: {
            select: {
              title: "label",
              kind: "kind",
              values: "values",
            },
            prepare: ({title, kind, values}) => ({
              title: title || "Axe",
              subtitle: [
                kind || "other",
                `${Array.isArray(values) ? values.length : 0} valeur(s)`,
              ].join(" • "),
            }),
          },
        }),
      ],
    }),
    defineField({
      name: "variantDefinitions",
      title: "Variantes V2",
      type: "array",
      group: "variations",
      description: "Chaque ligne represente une variante vendue. Utilisez cette structure en priorite pour les produits a variations complexes.",
      of: [
        defineArrayMember({
          type: "object",
          fields: [
            defineField({
              name: "isEnabled",
              title: "Active",
              type: "boolean",
              initialValue: true,
            }),
            defineField({name: "title", title: "Libelle variante", type: "string"}),
            defineField({name: "sku", title: "SKU", type: "string"}),
            defineField({name: "price", title: "Prix", type: "number"}),
            defineField({name: "regular_price", title: "Prix barre", type: "number"}),
            defineField({name: "sale_price", title: "Prix promo", type: "number"}),
            defineField({name: "stock_status", title: "Stock status", type: "string"}),
            defineField({name: "stock_quantity", title: "Quantite en stock", type: "number"}),
            defineField({
              name: "description",
              title: "Description de la variante",
              type: "text",
              rows: 5,
              description: "Texte affiche dans l'onglet Description lorsque cette variante est selectionnee.",
            }),
            defineField({
              name: "descriptionRich",
              title: "Description riche de la variante",
              type: "richText",
              description: "Optionnel. Remplace la description texte simple pour cette variante.",
            }),
            defineField({
              name: "weight",
              title: "Poids variante (g)",
              type: "string",
              description: "Poids specifique a cette variante en grammes. Exemple: 250",
            }),
            defineField({
              name: "length",
              title: "Longueur variante (cm)",
              type: "string",
              description: "Longueur specifique a cette variante en centimetres. Exemple: 20",
            }),
            defineField({
              name: "width",
              title: "Largeur variante (cm)",
              type: "string",
              description: "Largeur specifique a cette variante en centimetres. Exemple: 15",
            }),
            defineField({
              name: "height",
              title: "Hauteur variante (cm)",
              type: "string",
              description: "Hauteur specifique a cette variante en centimetres. Exemple: 3",
            }),
            defineField({
              name: "image",
              title: "Image",
              type: "object",
              fields: [
                defineField({
                  name: "asset",
                  title: "Image upload",
                  type: "image",
                  options: {hotspot: true},
                }),
                defineField({name: "src", type: "url"}),
                defineField({name: "url", type: "url"}),
              ],
            }),
            defineField({
              name: "selections",
              title: "Selections",
              type: "array",
              of: [
                defineArrayMember({
                  type: "object",
                  fields: [
                    defineField({
                      name: "axisKey",
                      title: "Cle axe",
                      type: "string",
                      validation: (r) => r.required(),
                    }),
                    defineField({
                      name: "value",
                      title: "Valeur",
                      type: "string",
                      validation: (r) => r.required(),
                    }),
                  ],
                  preview: {
                    select: {
                      title: "axisKey",
                      subtitle: "value",
                    },
                  },
                }),
              ],
              validation: (r) =>
                r.custom((value) =>
                  Array.isArray(value) && value.some((item) => item && typeof item === "object")
                    ? true
                    : "Ajoutez au moins une selection."
                ),
            }),
          ],
          preview: {
            select: {
              title: "title",
              sku: "sku",
              selections: "selections",
              isEnabled: "isEnabled",
            },
            prepare: ({title, sku, selections, isEnabled}) => ({
              title: title || sku || "Variante",
              subtitle: [
                isEnabled === false ? "Inactive" : "Active",
                Array.isArray(selections)
                  ? selections
                      .map((item) => {
                        const axisKey = item?.axisKey || "";
                        const value = item?.value || "";
                        return axisKey && value ? `${axisKey}: ${value}` : "";
                      })
                      .filter(Boolean)
                      .join(" • ")
                  : "",
              ]
                .filter(Boolean)
                .join(" • "),
            }),
          },
        }),
      ],
    }),
    defineField({
      name: "attributes",
      group: "general",
      type: "array",
      of: [
        defineArrayMember({
          type: "object",
          fields: [
            defineField({name: "id", type: "number"}),
            defineField({name: "name", type: "string"}),
            defineField({name: "slug", type: "string"}),
            defineField({name: "position", type: "number"}),
            defineField({name: "visible", type: "boolean"}),
            defineField({name: "variation", type: "boolean"}),
            defineField({
              name: "options",
              type: "array",
              of: [defineArrayMember({type: "string"})],
            }),
            defineField({name: "option", type: "string"}),
          ],
        }),
      ],
    }),
    defineField({
      name: "variations",
      group: "variations",
      type: "array",
      description: "Champ legacy conserve pour compatibilite avec l'ancien import Woo. La structure V2 ci-dessus est prioritaire.",
      of: [
        defineArrayMember({
          type: "object",
          fields: [
            defineField({name: "id", type: "number"}),
            defineField({name: "sku", type: "string"}),
            defineField({name: "price", type: "string"}),
            defineField({name: "regular_price", type: "string"}),
            defineField({name: "sale_price", type: "string"}),
            defineField({name: "stock_status", type: "string"}),
            defineField({name: "stock_quantity", type: "number"}),
            defineField({
              name: "description",
              title: "Description de la variante",
              type: "text",
              rows: 5,
              description: "Texte affiche dans l'onglet Description lorsque cette variante est selectionnee.",
            }),
            defineField({
              name: "descriptionRich",
              title: "Description riche de la variante",
              type: "richText",
              description: "Optionnel. Remplace la description texte simple pour cette variante.",
            }),
            defineField({name: "weight", title: "Poids variante (g)", type: "string"}),
            defineField({name: "length", title: "Longueur variante (cm)", type: "string"}),
            defineField({name: "width", title: "Largeur variante (cm)", type: "string"}),
            defineField({name: "height", title: "Hauteur variante (cm)", type: "string"}),
            defineField({
              name: "image",
              type: "object",
              fields: [
                defineField({
                  name: "asset",
                  title: "Image upload",
                  type: "image",
                  options: {hotspot: true},
                }),
                defineField({name: "id", type: "number"}),
                defineField({name: "src", type: "url"}),
                defineField({name: "url", title: "Image URL", type: "url"}),
                defineField({name: "alt", type: "string"}),
                defineField({name: "name", type: "string"}),
              ],
            }),
            defineField({
              name: "attributes",
              type: "array",
              of: [
                defineArrayMember({
                  type: "object",
                  fields: [
                    defineField({name: "id", type: "number"}),
                    defineField({name: "name", type: "string"}),
                    defineField({name: "slug", type: "string"}),
                    defineField({name: "option", type: "string"}),
                  ],
                }),
              ],
            }),
          ],
        }),
      ],
    }),
  ],
  preview: {
    select: {
      title: "title",
      subtitle: "slug.current",
      media: "mainImage",
      isActive: "isActive",
    },
    prepare: ({title, subtitle, media, isActive}) => ({
      title,
      subtitle: `${isActive === false ? "Inactive" : "Active"}${subtitle ? ` • ${subtitle}` : ""}`,
      media,
    }),
  },
});
