import type { GlobalConfig } from 'payload'

import { link } from '@/fields/link'
import { revalidateFooter } from './hooks/revalidateFooter'

export const Footer: GlobalConfig = {
  slug: 'footer',
  access: {
    read: () => true,
  },
  fields: [
    {
      type: 'tabs',
      tabs: [
        {
          label: 'Navigation',
          fields: [
            {
              name: 'navItems',
              type: 'array',
              label: 'Footer Links',
              fields: [
                link({
                  appearances: false,
                }),
              ],
              maxRows: 12,
              admin: {
                description: 'Main footer navigation links (Projects, Blog, About, Contact, Privacy, etc.)',
                initCollapsed: true,
                components: {
                  RowLabel: '@/Footer/RowLabel#RowLabel',
                },
              },
            },
            {
              name: 'socialLinks',
              type: 'array',
              label: 'Social Links',
              fields: [
                {
                  name: 'platform',
                  type: 'select',
                  required: true,
                  options: [
                    { label: 'LinkedIn', value: 'linkedin' },
                    { label: 'Twitter / X', value: 'twitter' },
                    { label: 'GitHub', value: 'github' },
                    { label: 'YouTube', value: 'youtube' },
                    { label: 'Facebook', value: 'facebook' },
                    { label: 'Instagram', value: 'instagram' },
                  ],
                },
                {
                  name: 'url',
                  type: 'text',
                  required: true,
                },
              ],
              admin: {
                description: 'Social media links',
                initCollapsed: true,
              },
            },
          ],
        },
        {
          label: 'Branding & Compliance',
          fields: [
            {
              name: 'euFundingLogos',
              type: 'array',
              label: 'EU Funding Logos',
              required: true,
              fields: [
                {
                  name: 'logo',
                  type: 'upload',
                  relationTo: 'media',
                  required: true,
                },
                {
                  name: 'alt',
                  type: 'text',
                  required: true,
                  admin: {
                    description: 'Alt text (e.g., "Financiado por la Unión Europea - NextGenerationEU")',
                  },
                },
                {
                  name: 'link',
                  type: 'text',
                  admin: {
                    description: 'Optional link URL',
                  },
                },
              ],
              admin: {
                description: 'MANDATORY for Kit Digital grant: EU, Next Generation EU, Plan de Recuperación logos',
                initCollapsed: false,
              },
            },
            {
              name: 'personalInfo',
              type: 'group',
              label: 'Personal Information',
              fields: [
                {
                  name: 'name',
                  type: 'text',
                  defaultValue: 'Oscar Gimenez',
                },
                {
                  name: 'professionalTitle',
                  type: 'text',
                  localized: true,
                  admin: {
                    description: 'Professional title or tagline (e.g., "Full Stack Developer", "Tech Consultant")',
                  },
                },
                {
                  name: 'location',
                  type: 'text',
                  localized: true,
                  admin: {
                    description: 'Location (e.g., "Barcelona, Spain")',
                  },
                },
                {
                  name: 'email',
                  type: 'email',
                },
                {
                  name: 'phone',
                  type: 'text',
                },
              ],
            },
          ],
        },
        {
          label: 'Newsletter',
          fields: [
            {
              name: 'newsletterEnabled',
              type: 'checkbox',
              defaultValue: false,
              admin: {
                description: 'Enable newsletter signup in footer',
              },
            },
            {
              name: 'newsletterHeading',
              type: 'text',
              localized: true,
              admin: {
                description: 'Newsletter section heading',
                condition: (data) => data.newsletterEnabled === true,
              },
            },
            {
              name: 'newsletterDescription',
              type: 'textarea',
              localized: true,
              admin: {
                description: 'Newsletter description text',
                condition: (data) => data.newsletterEnabled === true,
              },
            },
          ],
        },
      ],
    },
  ],
  hooks: {
    afterChange: [revalidateFooter],
  },
}
