import type { GlobalConfig } from 'payload'
import { area, group, href, list, plain, seo, txt } from '../fields'

const read = () => true
const content = { ar: 'صفحات الموقع', en: 'Site pages' }

// ---------------------------------------------------------------- site-wide
export const Settings: GlobalConfig = {
  slug: 'settings',
  label: { ar: 'إعدادات الموقع', en: 'Site settings' },
  admin: { group: content },
  access: { read },
  fields: [
    {
      type: 'tabs',
      tabs: [
        {
          label: { ar: 'الهوية والتواصل', en: 'Identity and contact' },
          fields: [
            txt('brandName', 'اسم الأكاديمية', 'Academy name', { required: true }),
            group('contact', 'التواصل', 'Contact', [
              plain('email', 'البريد', 'Email'),
              plain('phone', 'الهاتف', 'Phone'),
              plain('whatsapp', 'واتساب', 'WhatsApp', {
                admin: {
                  description: {
                    ar: 'بمفتاح الدولة، مثل 00201062163038. الرقم يُعرض مرتّباً، والضغط عليه يفتح واتساب على محادثة معنا.',
                    en: 'With the country code, for example 00201062163038. It is shown tidily, and a tap opens WhatsApp on a chat with us.',
                  },
                },
              }),
              txt('waText', 'أول سطر في محادثة واتساب', 'First line typed in the WhatsApp chat', {
                admin: { description: { ar: 'يظهر مكتوباً في المحادثة عند فتحها، فالزائر يضغط إرسال فقط.', en: 'It is already typed when the chat opens; the visitor only presses send.' } },
              }),
              area('lead', 'جملة التواصل', 'Contact line', {
                admin: { description: { ar: 'تظهر فوق وسائل التواصل في الفوتر وفي صفحة الأسعار.', en: 'Shown above the contact details in the footer and on the pricing page.' } },
              }),
              plain('youtube', 'قناة يوتيوب', 'YouTube channel'),
            ]),
            plain('platformUrl', 'عنوان منصة التعلّم', 'Learning platform address', {
              admin: {
                description: {
                  ar: 'مثل https://learn.thinkera.academy. يظهر في الرأس زر «دخول المنصة».',
                  en: 'For example https://learn.thinkera.academy. The header shows a sign-in button.',
                },
              },
            }),
            href('freeLessonHref'),
            plain('notifyEmail', 'بريد إشعارات الطلبات', 'Where new requests are mailed', {
              admin: {
                description: {
                  ar: 'كل طلب اهتمام جديد بيتبعت على البريد ده. سيبه فاضي عشان نستخدم NOTIFY_EMAIL من ملف .env.',
                  en: 'Every new interest request is mailed here. Leave it empty to use NOTIFY_EMAIL from .env.',
                },
              },
            }),
            group('currency', 'العملة', 'Currency', [plain('code', 'الرمز', 'Code'), txt('label', 'الاسم المعروض', 'Shown as')]),
          ],
        },
        {
          label: { ar: 'القائمة والأزرار', en: 'Menu and buttons' },
          fields: [
            list('nav', 'القائمة الرئيسية', 'Main menu', [
              txt('label', 'النص', 'Label', { required: true, localized: false }),
              href(),
            ]),
            group('cta', 'نصوص الأزرار', 'Button labels', [
              txt('free', 'مشاهدة الدرس المجاني', 'Free lesson'),
              txt('all', 'كل الدورات', 'All courses'),
              txt('primary', 'تفاصيل الدورة', 'Course details'),
              txt('enrol', 'سجّل اهتمامك', 'Register interest'),
              txt('subscribe', 'الاشتراك على المنصة', 'Enrol on the platform'),
              txt('notify', 'أبلغوني عند الإطلاق', 'Notify me'),
              txt('youtube', 'القناة على يوتيوب', 'YouTube'),
            ]),
            group('ui', 'نصوص الواجهة', 'Interface text', [
              txt('langSwitch', 'زر تبديل اللغة', 'Language switch'),
              txt('menu', 'زر القائمة (الموبايل)', 'Menu button (mobile)'),
              txt('skip', 'انتقل إلى المحتوى', 'Skip link'),
              txt('signIn', 'دخول المنصة', 'Sign in'),
            ]),
            group('status', 'حالات الدورات', 'Course status labels', [
              txt('live', 'متاحة الآن', 'Available now'),
              txt('partial', 'متاحة جزئياً', 'Partly available'),
              txt('soon', 'قريباً', 'Coming soon'),
            ]),
          ],
        },
        {
          label: { ar: 'التذييل', en: 'Footer' },
          fields: [
            group('footer', 'التذييل', 'Footer', [
              area('tagline', 'السطر التعريفي', 'Tagline'),
              txt('coursesHeading', 'عنوان عمود الدورات', 'Courses column heading'),
              txt('academyHeading', 'عنوان عمود الأكاديمية', 'Academy column heading'),
              list('links', 'روابط الأكاديمية', 'Academy links', [txt('label', 'النص', 'Label', { required: true, localized: false }), href()]),
              txt('rights', 'حقوق النشر', 'Rights line'),
            ]),
          ],
        },
      ],
    },
  ],
}

// ---------------------------------------------------------------- home page
const pair = (a: [string, string, string], b: [string, string, string]) => [
  txt(a[0], a[1], a[2], { required: true, localized: false }),
  (b[0] === 'text' ? area : txt)(b[0], b[1], b[2], { localized: false }),
]

export const Home: GlobalConfig = {
  slug: 'home',
  label: { ar: 'الصفحة الرئيسية', en: 'Home page' },
  admin: { group: content },
  access: { read },
  fields: [
    seo(),
    {
      type: 'tabs',
      tabs: [
        {
          label: { ar: 'الواجهة', en: 'Hero' },
          fields: [
            txt('eyebrow', 'السطر العلوي', 'Eyebrow'),
            txt('h1', 'العنوان الرئيسي', 'Main heading', { required: true }),
            txt('h1Accent', 'تكملة العنوان (بلون مميز)', 'Heading accent'),
            area('lead', 'الفقرة الافتتاحية', 'Lead'),
            list('facts', 'الأرقام', 'Figures', pair(['n', 'الرقم', 'Figure'], ['label', 'الوصف', 'Label'])),
            { name: 'heroImage', type: 'upload', relationTo: 'media', label: { ar: 'صورة الواجهة', en: 'Hero image' } },
          ],
        },
        {
          label: { ar: 'فوق الكتاب', en: 'Beyond the book' },
          fields: [
            txt('bookTitle', 'العنوان', 'Heading'),
            area('bookLead', 'الفقرة', 'Lead'),
            txt('bookBarTitle', 'عنوان الشريط', 'Bar title'),
            list('bookBar', 'أجزاء الشريط', 'Bar segments', [
              ...pair(['n', 'العدد', 'Count'], ['label', 'الوصف', 'Label']),
              {
                name: 'kind',
                type: 'select',
                required: true,
                label: { ar: 'اللون', en: 'Colour' },
                options: [
                  { value: 'book', label: { ar: 'الكتاب', en: 'Book' } },
                  { value: 'added', label: { ar: 'مضاف', en: 'Added' } },
                  { value: 'lab', label: { ar: 'معمل', en: 'Lab' } },
                  { value: 'project', label: { ar: 'مشروع', en: 'Project' } },
                ],
              },
            ]),
            area('bookCode', 'ملاحظة الكود', 'Code note'),
            txt('layersTitle', 'عنوان الطبقات', 'Layers heading'),
            list('layers', 'الطبقات', 'Layers', [
              txt('badge', 'الشارة', 'Badge', { required: true, localized: false }),
              txt('name', 'الاسم', 'Name', { required: true, localized: false }),
              area('text', 'الشرح', 'Text', { localized: false }),
              {
                name: 'plain',
                type: 'checkbox',
                label: { ar: 'بلا شارة (محتوى الكتاب)', en: 'No badge (book content)' },
              },
            ]),
            area('paths', 'فقرة المسارين', 'Two paths'),
          ],
        },
        {
          label: { ar: 'الخطوات والموقف', en: 'Steps and scene' },
          fields: [
            txt('stepsTitle', 'عنوان الخطوات', 'Steps heading'),
            list('steps', 'الخطوات', 'Steps', [
              txt('n', 'الرقم', 'Number', { required: true, localized: false }),
              txt('title', 'العنوان', 'Title', { required: true, localized: false }),
              area('text', 'الشرح', 'Text', { localized: false }),
            ]),
            txt('lifeTitle', 'عنوان الموقف', 'Scene heading'),
            area('lifeText', 'نص الموقف', 'Scene text'),
            { name: 'lifeImage', type: 'upload', relationTo: 'media', label: { ar: 'صورة الموقف', en: 'Scene image' } },
            list('lifeBoxes', 'المربعات', 'Boxes', pair(['title', 'العنوان', 'Title'], ['text', 'النص', 'Text'])),
          ],
        },
        {
          label: { ar: 'الوحدات والفريق', en: 'Units and team' },
          fields: [
            txt('unitsTitle', 'عنوان الوحدات', 'Units heading'),
            area('unitsLead', 'فقرة الوحدات', 'Units lead'),
            {
              name: 'unitsCourse',
              type: 'relationship',
              relationTo: 'courses',
              label: { ar: 'الدورة التي تُعرض وحداتها', en: 'Course whose units are shown' },
            },
            txt('peopleTitle', 'عنوان الفريق', 'Team heading'),
            list('people', 'من يقف خلف المحتوى', 'Who is behind the content', pair(['name', 'الاسم', 'Name'], ['text', 'النبذة', 'Bio'])),
          ],
        },
        {
          label: { ar: 'الدورات والأسئلة', en: 'Courses and FAQ' },
          fields: [
            txt('coursesTitle', 'عنوان الدورات', 'Courses heading'),
            area('coursesLead', 'فقرة الدورات', 'Courses lead'),
            txt('ctaTitle', 'عنوان الدعوة', 'Call to action heading'),
            area('ctaLead', 'فقرة الدعوة', 'Call to action text'),
            txt('faqTitle', 'عنوان الأسئلة', 'FAQ heading'),
            list('faq', 'الأسئلة المتكرّرة', 'FAQ', pair(['q', 'السؤال', 'Question'], ['text', 'الإجابة', 'Answer'])),
          ],
        },
      ],
    },
  ],
}

// ---------------------------------------------------------------- catalogue and course pages
export const Catalogue: GlobalConfig = {
  slug: 'catalogue',
  label: { ar: 'صفحة الدورات', en: 'Courses page' },
  admin: { group: content },
  access: { read },
  fields: [
    seo(),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    area('lead', 'الفقرة', 'Lead'),
    group('labels', 'نصوص صفحة الدورة', 'Course page labels', [
      txt('back', 'رابط الرجوع', 'Back link'),
      txt('outcomes', 'عنوان المخرجات', 'Outcomes heading'),
      txt('audience', 'عنوان الجمهور', 'Audience heading'),
      txt('instruction', 'لغة الشرح', 'Language of instruction'),
      txt('level', 'المستوى', 'Level'),
      txt('units', 'عنوان الوحدات', 'Units heading'),
      txt('unitsLead', 'شرح عدّاد الوحدات', 'Units count note'),
      txt('preview', 'عنوان المعاينة', 'Preview heading'),
      area('previewNote', 'فقرة المعاينة', 'Preview text'),
      txt('freeLessons', 'عنوان الدروس المجانية', 'Free lessons heading'),
      area('freeLessonsNote', 'فقرة الدروس المجانية', 'Free lessons text'),
      txt('watch', 'زر المشاهدة', 'Watch button'),
      txt('lessonsWord', 'كلمة «درساً»', 'Word for lessons'),
      txt('labsWord', 'كلمة «معملاً»', 'Word for labs'),
      txt('projectsWord', 'كلمة «مشروعات»', 'Word for projects'),
      txt('fromBook', 'من الكتاب', 'From the book'),
      txt('added', 'إضافية', 'Added'),
      txt('addedUnit', 'وحدة مضافة', 'Added unit'),
      txt('priceWas', 'وصف السعر المشطوب', 'Label of the struck-through price', {
        admin: { description: { ar: 'يقرأه قارئ الشاشة فقط، فيعرف أن الرقم المشطوب هو السعر العادي.', en: 'Read by a screen reader only, so the struck-through figure is understood as the normal price.' } },
      }),
      txt('offerUntil', 'جملة انتهاء العرض', 'Offer deadline line', {
        admin: { description: { ar: 'اكتب {date} مكان التاريخ، مثل: العرض لحد {date}.', en: 'Write {date} where the date goes, for example: offer runs until {date}.' } },
      }),
    ]),
  ],
}

// ---------------------------------------------------------------- pricing and enrolment
export const Pricing: GlobalConfig = {
  slug: 'pricing',
  label: { ar: 'صفحة الأسعار والتسجيل', en: 'Pricing page' },
  admin: { group: content },
  access: { read },
  fields: [
    seo(),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    area('lead', 'الفقرة', 'Lead'),
    txt('plansTitle', 'عنوان الخطط', 'Plans heading'),
    list('plans', 'الخطط', 'Plans', [
      txt('name', 'اسم الخطة', 'Plan name', { required: true, localized: false }),
      area('text', 'الوصف', 'Description', { localized: false }),
      {
        name: 'items',
        type: 'array',
        label: { ar: 'ما تشمله', en: 'Includes' },
        fields: [{ name: 'text', type: 'text', required: true, label: { ar: 'النص', en: 'Text' } }],
      },
      txt('price', 'السعر (نص)', 'Price (as text)', {
        localized: false,
        admin: { description: { ar: 'فارغ = يظهر سعر الدورة الأولى وملاحظته.', en: 'Empty = the first course’s price and note.' } },
      }),
    ]),
    txt('formTitle', 'عنوان النموذج', 'Form heading'),
    area('formLead', 'فقرة النموذج', 'Form lead'),
    group('fields', 'حقول النموذج', 'Form fields', [
      txt('name', 'الاسم', 'Name'),
      txt('email', 'البريد', 'Email'),
      txt('phone', 'الموبايل', 'Mobile'),
      txt('role', 'الصفة', 'Role'),
      txt('course', 'الدورة', 'Course'),
      txt('note', 'السؤال', 'Question'),
    ]),
    list('roles', 'خيارات الصفة', 'Role options', [txt('label', 'الخيار', 'Option', { required: true, localized: false })]),
    txt('submit', 'زر الإرسال', 'Submit button'),
    area('privacy', 'ملاحظة الخصوصية', 'Privacy note'),
    area('sent', 'رسالة الشكر بعد الإرسال', 'Thank-you message'),
    area('invalid', 'رسالة الخطأ', 'Error message'),
  ],
}

// ---------------------------------------------------------------- about
// ---------------------------------------------------------------- contact
export const Contact: GlobalConfig = {
  slug: 'contactpage',
  label: { ar: 'صفحة اتصل بنا', en: 'Contact page' },
  admin: { group: content },
  access: { read },
  fields: [
    seo(),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    area('lead', 'الفقرة', 'Lead'),
    txt('formTitle', 'عنوان النموذج', 'Form heading'),
    area('formLead', 'فقرة النموذج', 'Form lead'),
    txt('waysTitle', 'عنوان وسائل التواصل', 'Contact ways heading'),
    group('reassure', 'رسالة الطمأنة', 'Reassurance', [
      txt('title', 'العنوان', 'Heading'),
      area('text', 'النص', 'Text'),
    ]),
  ],
}

export const About: GlobalConfig = {
  slug: 'about',
  label: { ar: 'صفحة عن الأكاديمية', en: 'About page' },
  admin: {
    group: content,
    description: { ar: 'بطاقات الفريق تأتي من الصفحة الرئيسية (تبويب «الوحدات والفريق»).', en: 'The team cards come from the home page (tab “Units and team”).' },
  },
  access: { read },
  fields: [
    seo(),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    area('lead', 'الفقرة', 'Lead'),
    txt('peopleTitle', 'عنوان الفريق', 'Team heading'),
    txt('principlesTitle', 'عنوان القواعد', 'Principles heading'),
    list('principles', 'القواعد', 'Principles', [area('text', 'القاعدة', 'Principle', { required: true, localized: false })]),
    list('sections', 'أقسام', 'Sections', [
      txt('title', 'العنوان', 'Title', { required: true, localized: false }),
      area('text', 'النص', 'Text', { localized: false }),
    ]),
  ],
}
