import type { Field } from 'payload'

export const footerFields: Field[] = [
  {
    name: 'variant',
    type: 'select',
    required: true,
    defaultValue: 'default',
    options: [
      { label: 'Default (site)', value: 'default' },
      { label: 'Landing (minimal)', value: 'landing' },
      { label: 'Campaign (Newsletter & Apps)', value: 'campaign' },
    ],
  },
  {
    name: 'copyright',
    type: 'text',
    defaultValue: '© Karma Group',
  },
  // Default footer links (columns)
  {
    name: 'linkColumns',
    type: 'array',
    label: 'Footer link columns',
    admin: {
      condition: (_, siblingData) => siblingData?.variant === 'default',
      initCollapsed: true,
    },
    fields: [
      { name: 'heading', type: 'text', required: true },
      {
        name: 'links',
        type: 'array',
        fields: [
          { name: 'label', type: 'text', required: true },
          { name: 'href', type: 'text', required: true },
          { name: 'openInNewTab', type: 'checkbox', defaultValue: false },
        ],
      },
    ],
  },
  // Landing footer: keep it light (legal links)
  {
    name: 'legalLinks',
    type: 'array',
    label: 'Legal links',
    admin: {
      condition: (_, siblingData) => ['landing', 'campaign'].includes(siblingData?.variant),
      initCollapsed: true,
    },
    fields: [
      { name: 'label', type: 'text', required: true },
      { name: 'href', type: 'text', required: true },
    ],
  },
  // Campaign specific fields
  {
    name: 'newsletter',
    type: 'group',
    admin: {
      condition: (_, siblingData) => siblingData?.variant === 'campaign',
    },
    fields: [
      { name: 'heading', type: 'text', defaultValue: 'Newsletter' },
      { name: 'description', type: 'textarea' },
      {
        name: 'form',
        type: 'relationship',
        relationTo: 'forms',
        required: true,
        admin: {
          description: 'Select the form to display in the newsletter section.',
        },
      },

    ],
  },
  {
    name: 'socialLinks',
    type: 'array',
    admin: {
      condition: (_, siblingData) => siblingData?.variant === 'campaign',
    },
    fields: [
      {
        name: 'platform',
        type: 'select',
        options: [
          { label: 'Facebook', value: 'facebook' },
          { label: 'Instagram', value: 'instagram' },
          { label: 'Twitter / X', value: 'twitter' },
          { label: 'LinkedIn', value: 'linkedin' },
          { label: 'YouTube', value: 'youtube' },
        ],
        required: true,
      },
      { name: 'url', type: 'text', required: true },
    ],
  },
  {
    name: 'appLinks',
    type: 'group',
    label: 'App Store Links',
    admin: {
      condition: (_, siblingData) => siblingData?.variant === 'campaign',
    },
    fields: [
      { name: 'appLabel', type: 'text', label: 'App Section Label', defaultValue: 'Karma Club App' },
      { name: 'iosUrl', type: 'text', label: 'Apple App Store URL' },
      { name: 'androidUrl', type: 'text', label: 'Google Play Store URL' },
    ],
  },
]
