import { defineConfig, collection, fields, singleton } from '@keystatic/core';

export default defineConfig({
  storage: {
    kind: 'local',
  },
  collections: {
    services: collection({
      label: 'Servicios',
      slugField: 'slug',
      path: 'src/content/services/*',
      schema: {
        slug: fields.text({
          label: 'Slug (URL)',
          validation: { length: { min: 1, max: 80 } },
        }),
        category: fields.select({
          label: 'Categoría',
          options: [
            { label: 'Hosting & Correo', value: 'hosting' },
            { label: 'Diseño & Contenido', value: 'diseno' },
            { label: 'Infraestructura', value: 'infraestructura' },
          ],
          defaultValue: 'hosting',
        }),
        icon: fields.text({
          label: 'Ícono (MailIcon, WordpressIcon, CodeIcon, ShopIcon, TranslateIcon, ServerIcon)',
        }),
        order: fields.number({
          label: 'Orden',
          defaultValue: 0,
        }),
        name_es: fields.text({ label: 'Nombre (ES)' }),
        name_en: fields.text({ label: 'Nombre (EN)' }),
        shortDescription_es: fields.text({ label: 'Descripción corta (ES)', multiline: true }),
        shortDescription_en: fields.text({ label: 'Descripción corta (EN)', multiline: true }),
        body_es: fields.mdx({ label: 'Descripción completa (ES)' }),
        body_en: fields.mdx({ label: 'Descripción completa (EN)' }),
        features_es: fields.array(fields.text({ label: 'Feature' }), {
          label: 'Features (ES)',
          itemLabel: (props) => props.value,
        }),
        features_en: fields.array(fields.text({ label: 'Feature' }), {
          label: 'Features (EN)',
          itemLabel: (props) => props.value,
        }),
      },
    }),

    tutorials: collection({
      label: 'Instructivos',
      slugField: 'slug',
      path: 'src/content/tutorials/*',
      schema: {
        slug: fields.text({
          label: 'Slug (URL)',
          validation: { length: { min: 1, max: 80 } },
        }),
        category: fields.select({
          label: 'Categoría',
          options: [
            { label: 'Correo', value: 'correo' },
            { label: 'WordPress', value: 'wordpress' },
            { label: 'Dominios', value: 'dominios' },
            { label: 'cPanel', value: 'cpanel' },
            { label: 'SSL', value: 'ssl' },
            { label: 'Backups', value: 'backups' },
          ],
        }),
        updatedAt: fields.date({
          label: 'Última actualización',
        }),
        title_es: fields.text({ label: 'Título (ES)' }),
        title_en: fields.text({ label: 'Título (EN)' }),
        summary_es: fields.text({ label: 'Resumen (ES)', multiline: true }),
        summary_en: fields.text({ label: 'Resumen (EN)', multiline: true }),
        content_es: fields.mdx({ label: 'Contenido (ES)' }),
        content_en: fields.mdx({ label: 'Contenido (EN)' }),
      },
    }),
  },
  singletons: {
    siteSettings: singleton({
      label: 'Configuración del sitio',
      path: 'src/content/settings/site',
      schema: {
        contactEmail: fields.text({ label: 'Email de contacto' }),
        whatsappNumber: fields.text({ label: 'WhatsApp (con código país, sin +)' }),
        whatsappDefaultMessage_es: fields.text({ label: 'Mensaje inicial WhatsApp (ES)' }),
        whatsappDefaultMessage_en: fields.text({ label: 'Mensaje inicial WhatsApp (EN)' }),
        addressLine: fields.text({ label: 'Dirección (línea corta)' }),
        socialLinkedin: fields.url({ label: 'LinkedIn URL' }),
        socialGithub: fields.url({ label: 'GitHub URL' }),
      },
    }),
  },
});
