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 }),
            txt('banner', 'الشريط العلوي', 'Top strip', {
              admin: {
                description: {
                  ar: 'سطر واحد فوق القائمة في كل الصفحات. اتركه فارغاً فلا يظهر الشريط أصلاً.',
                  en: 'One line above the menu on every page. Leave it empty and the strip is not shown at all.',
                },
              },
            }),
            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'),
              txt('light', 'التبديل للوضع الفاتح', 'Switch to light'),
              txt('dark', 'التبديل للوضع الداكن', 'Switch to dark'),
              txt('close', 'إغلاق', 'Close'),
            ]),
            group('status', 'حالات المناهج', 'Course status labels', [
              txt('live', 'متاح الآن', 'Available now'),
              txt('partial', 'متاح جزئياً', 'Partly available'),
              txt('soon', 'قريباً', 'Coming soon'),
            ]),
          ],
        },
        {
          label: { ar: 'الدعم والمساعدة', en: 'Support and help' },
          admin: {
            description: {
              ar: 'الدعم المباشر بيفتح محادثة مع شخص حقيقي على خادم الدعم بتاعنا. تشغيله وإطفاؤه ورمزه من هنا، مش من ملف env.',
              en: 'Live support opens a conversation with a real person on our own support server. Switching it on or off, and its token, are set here rather than in the env file.',
            },
          },
          fields: [
            group('support', 'الدعم المباشر', 'Live support', [
              {
                name: 'enabled',
                type: 'checkbox',
                label: { ar: 'شغّال', en: 'Enabled' },
                defaultValue: false,
                admin: {
                  description: {
                    ar: 'لما يكون مقفول، مافيش أي كود بيتحمّل من خادم الدعم أصلاً.',
                    en: 'When off, nothing at all is loaded from the support server.',
                  },
                },
              },
              plain('baseUrl', 'عنوان خادم الدعم', 'Support server address', {
                admin: {
                  description: {
                    ar: 'مثل https://chat.thinkera.academy — من غير / في الآخر.',
                    en: 'For example https://chat.thinkera.academy — no trailing slash.',
                  },
                },
              }),
              plain('websiteToken', 'رمز الموقع', 'Website token', {
                admin: {
                  description: {
                    ar: 'الرمز اللي خادم الدعم بيديه لكل موقع. مش سر، بيظهر في كود الصفحة، لكنه بيحدد صندوق المحادثات اللي الرسايل بتروح له.',
                    en: 'The token the support server issues per website. Not a secret — it appears in the page source — but it decides which inbox the messages land in.',
                  },
                },
              }),
            ]),
            group('chat', 'فقاعة المساعدة (متوقفة — مش بتظهر على الموقع)', 'Help bubble (retired — not shown on the site)', [
              txt('title', 'العنوان', 'Title', {
                admin: {
                  description: {
                    ar: 'الفقاعة دي اتستبدلت بالدعم المباشر فوق. النصوص سايبة هنا عشان ماتضيعش، وتعديلها ماليهوش أي أثر على الموقع.',
                    en: 'This bubble was replaced by Live support above. The text is kept so it is not lost; editing it has no effect on the site.',
                  },
                },
              }),
              area('greeting', 'جملة الترحيب', 'Greeting'),
              list('items', 'الأسئلة وإجاباتها', 'Questions and answers', [
                txt('q', 'السؤال (زر)', 'Question (a button)', { required: true, localized: false }),
                area('a', 'الإجابة', 'Answer', { required: true, localized: false }),
              ]),
              txt('placeholder', 'نص خانة الكتابة', 'Input placeholder'),
              txt('send', 'زر الإرسال', 'Send button'),
              area('disclaimer', 'التنويه أسفل الخانة', 'Note under the box', {
                admin: {
                  description: {
                    ar: 'لازم يوضّح أن الرسالة بتتفتح على واتساب ومحدش بيرد هنا.',
                    en: 'It must make clear the message opens in WhatsApp and nobody answers inside the bubble.',
                  },
                },
              }),
            ]),
          ],
        },
        {
          label: { ar: 'التذييل', en: 'Footer' },
          fields: [
            group('footer', 'التذييل', 'Footer', [
              area('tagline', 'السطر التعريفي', 'Tagline'),
              txt('coursesHeading', 'عنوان عمود المناهج', 'Courses column heading'),
              txt('academyHeading', 'عنوان عمود الأكاديمية', 'Academy column heading'),
              txt('contactHeading', 'عنوان عمود التواصل', 'Contact column heading'),
              txt('socialHeading', 'عنوان صف السوشيال ميديا', 'Social row heading'),
              list('links', 'روابط الأكاديمية', 'Academy links', [txt('label', 'النص', 'Label', { required: true, localized: false }), href()]),
              txt('rights', 'حقوق النشر', 'Rights line'),
            ]),
            // Not localized: one row per network, the same address in both editions. A list that
            // was localized would make an editor paste every link twice and let the two drift.
            list('social', 'روابط التواصل الاجتماعي', 'Social links', [
              {
                name: 'network',
                type: 'select',
                required: true,
                label: { ar: 'الشبكة', en: 'Network' },
                options: [
                  { value: 'facebook', label: 'Facebook' },
                  { value: 'instagram', label: 'Instagram' },
                  { value: 'linkedin', label: 'LinkedIn' },
                  { value: 'youtube', label: 'YouTube' },
                  { value: 'tiktok', label: 'TikTok' },
                  { value: 'telegram', label: 'Telegram' },
                  { value: 'twitter', label: 'X (Twitter)' },
                  { value: 'whatsapp', label: 'WhatsApp' },
                ],
              },
              plain('url', 'الرابط', 'Address', {
                required: true,
                admin: {
                  description: {
                    ar: 'العنوان الكامل للصفحة، يبدأ بـ https:// — الصف اللي رابطه فاضي ما بيظهرش.',
                    en: 'The page’s full address, starting with https:// — a row with no address is not shown.',
                  },
                },
              }),
            ], {
              localized: false,
              admin: {
                description: {
                  ar: 'تظهر أيقونات في تذييل كل الصفحات، بالترتيب المكتوب هنا. امسح الصف عشان تشيل الأيقونة.',
                  en: 'Shown as icons in the footer of every page, in this order. Delete a row to remove its icon.',
                },
              },
            }),
          ],
        },
      ],
    },
  ],
}

// ---------------------------------------------------------------- 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' } },
            txt('noteOne', 'الملاحظة العائمة الأولى', 'First floating note', {
              admin: { description: { ar: 'سطر قصير يظهر على زاوية صورة الواجهة.', en: 'A short line on the corner of the hero art.' } },
            }),
            txt('noteTwo', 'الملاحظة العائمة الثانية', 'Second floating note'),
            txt('browseCta', 'زر «شوف الكورسات»', 'Browse-courses button'),
            txt('categoriesCta', 'زر «اختار مجالك»', 'Explore-categories button'),
          ],
        },
        {
          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'),
            // The section above is the promise of the school courses, and it is the strongest thing on the page.
            // The work courses need their own, because they have no syllabus to cover and no textbook to finish,
            // and borrowing the school promise for them would be a claim nobody could stand behind.
            txt('workTitle', 'عنوان وعد مناهج الشغل', 'Work courses heading'),
            area('workLead', 'فقرة وعد مناهج الشغل', 'Work courses text'),
          ],
        },
        {
          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: 'Storefront sections' },
          admin: {
            description: {
              ar: 'الأقسام الثلاثة في الصفحة الرئيسية: المجالات، ثم الكورسات المختارة، ثم «ليه Thinkera».',
              en: 'The three bands on the home page: learning areas, featured courses, then “why Thinkera”.',
            },
          },
          fields: [
            txt('catEyebrow', 'السطر العلوي للمجالات', 'Areas eyebrow'),
            txt('catTitle', 'عنوان المجالات', 'Areas heading'),
            area('catText', 'فقرة المجالات', 'Areas text'),
            txt('catLink', 'رابط «كل التصنيفات»', 'All-categories link text'),
            txt('featuredEyebrow', 'السطر العلوي للكورسات المختارة', 'Featured eyebrow'),
            txt('featuredLink', 'رابط «شوف كل الكورسات»', 'All-courses link text'),
            txt('whyEyebrow', 'السطر العلوي لـ«ليه Thinkera»', 'Why eyebrow'),
            txt('whyTitle', 'عنوان «ليه Thinkera»', 'Why heading'),
            list('why', 'المزايا الثلاث', 'The three points', [
              {
                name: 'icon',
                type: 'select',
                label: { ar: 'الأيقونة', en: 'Icon' },
                defaultValue: 'book',
                options: [
                  { value: 'book', label: { ar: 'كتاب', en: 'Book' } },
                  { value: 'target', label: { ar: 'هدف', en: 'Target' } },
                  { value: 'clock', label: { ar: 'ساعة', en: 'Clock' } },
                  { value: 'check', label: { ar: 'علامة صح', en: 'Tick' } },
                  { value: 'layers', label: { ar: 'طبقات', en: 'Layers' } },
                  { value: 'ai', label: { ar: 'ذكاء اصطناعي', en: 'AI' } },
                ],
              },
              txt('title', 'العنوان', 'Title', { required: true, localized: false }),
              area('text', 'الشرح', 'Text', { localized: false }),
            ]),
          ],
        },
        {
          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('filters', 'نصوص الفلاتر والترتيب', 'Filter and sort labels', [
      txt('search', 'خانة البحث', 'Search box'),
      txt('category', 'التصنيف', 'Category'),
      txt('level', 'المستوى', 'Level'),
      txt('status', 'الإتاحة', 'Availability'),
      txt('all', 'الكل', 'All'),
      txt('allLevels', 'كل المستويات', 'All levels'),
      txt('results', 'ما يأتي بعد العدد والمعدود في النتائج', 'What follows the counted noun in the result line', {
        admin: { description: { ar: 'تظهر هكذا: «6 مناهج في النتايج» — اكتب «في النتايج» فقط؛ كلمة «مناهج» تُختار تلقائياً حسب العدد.', en: 'Shown as “6 courses found” — write only “found”; the word “courses” is chosen by the number.' } },
      }),
      txt('sort', 'ترتيب حسب', 'Sort by'),
      txt('sortDefault', 'الترتيب الافتراضي', 'Default order'),
      txt('sortPrice', 'السعر الأقل', 'Lowest price'),
      txt('empty', 'لا نتائج', 'Nothing matched'),
      txt('page', 'كلمة «صفحة»', 'The word “page”'),
    ]),
    group('count', 'المعدود: كلمة «منهج» مع العدد', 'The counted noun: “course” with a number', [
      // Arabic has four forms after a number and English two. Writing them out is the only way the
      // site can print «4 مناهج» rather than «4 منهج»; Intl.PluralRules picks which one, per language.
      txt('one', '١ (منهج)', '1 (course)'),
      txt('two', '٢ (منهجين)', '2 — not used in English'),
      txt('few', '٣ إلى ١٠ (مناهج)', '3 to 10'),
      txt('many', '١١ فأكثر (منهجاً)', '11 and above'),
      txt('other', 'غير ذلك / الافتراضي', 'Other (the default)', {
        admin: { description: { ar: 'يُستخدم عند عدم ملء الخانة المناسبة. في الإنجليزية هذه هي صيغة الجمع.', en: 'Used when the matching box is empty. In English this is the plural.' } },
      }),
    ]),
    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 (school courses)'),
      // A work course has no textbook, and «معتمد» would claim an accreditation nobody granted. So the word is
      // chosen by the course's track: «من الكتاب» keeps its force where it is true — it tells a parent the
      // lesson is in the ministry's own book — and the work courses say «أساسي» instead.
      txt('fromCore', 'أساسي (مناهج الشغل)', 'Core (work courses)'),
      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}.' } },
      }),
    ]),
  ],
}

// ---------------------------------------------------------------- the categories page
export const Categories: GlobalConfig = {
  slug: 'categories',
  label: { ar: 'صفحة التصنيفات', en: 'Categories page' },
  admin: {
    group: content,
    description: {
      ar: 'التصنيفات نفسها تأتي من المنصة، وعدد الكورسات تحت كل تصنيف يُحسب تلقائياً. هنا عنوان الصفحة ومقدمتها فقط.',
      en: 'The categories themselves come from the learning platform, and the count under each is worked out automatically. Only the page’s heading and intro are set here.',
    },
  },
  access: { read },
  fields: [
    seo(),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    area('lead', 'الفقرة', 'Lead'),
    txt('featuredTitle', 'عنوان الكورسات المختارة', 'Featured courses heading'),
    area('featuredLead', 'فقرة الكورسات المختارة', 'Featured courses lead'),
  ],
}

// ---------------------------------------------------------------- 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 }),
    ]),
  ],
}

// ---------------------------------------------------------------- the two legal pages
/**
 * «سياسة الخصوصية» and «شروط الاستخدام» are the same shape: a heading, the date the text last changed, a
 * paragraph, numbered sections and a closing line on how to reach us. One builder, two globals, one renderer
 * on the site — a legal page that is edited in two different shapes drifts, and these two must not.
 *
 * A section's text is read as it is written: an empty line starts a new paragraph, and a line beginning with
 * «- » is an item in a list. That is all the formatting a legal page needs, and it keeps the text editable by
 * somebody who is not a developer.
 */
const legal = (slug: 'privacy' | 'terms', ar: string, en: string, note: { ar: string; en: string }): GlobalConfig => ({
  slug,
  label: { ar, en },
  admin: { group: content, description: note },
  access: { read },
  fields: [
    seo(),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    txt('updated', 'تاريخ آخر تحديث', 'Last updated', {
      admin: {
        description: {
          ar: 'يظهر تحت العنوان. غيّره كل ما تعدّل النص — هو اللي بيقول للزائر إن الصفحة اتغيرت.',
          en: 'Shown under the heading. Change it whenever the text changes — it is what tells a visitor the page moved.',
        },
      },
    }),
    area('lead', 'الفقرة التمهيدية', 'Lead'),
    list('sections', 'الأقسام', 'Sections', [
      txt('title', 'العنوان', 'Title', { required: true, localized: false }),
      area('text', 'النص', 'Text', {
        required: true,
        localized: false,
        admin: {
          description: {
            ar: 'سطر فاضي بين الفقرات. السطر اللي بيبدأ بـ «- » يبقى عنصر في قائمة.',
            en: 'An empty line between paragraphs. A line starting with “- ” becomes an item in a list.',
          },
        },
      }),
    ]),
    area('closing', 'سطر التواصل في الآخر', 'Closing contact line'),
  ],
})

export const Privacy = legal('privacy', 'صفحة سياسة الخصوصية', 'Privacy policy page', {
  ar: 'بيانات التواصل (البريد والواتساب) بتيجي من «إعدادات الموقع»، فما تكتبهاش هنا تاني.',
  en: 'The contact details (email and WhatsApp) come from Site settings, so do not write them here again.',
})

export const Terms = legal('terms', 'صفحة شروط الاستخدام', 'Terms of service page', {
  ar: 'بيانات التواصل (البريد والواتساب) بتيجي من «إعدادات الموقع»، فما تكتبهاش هنا تاني.',
  en: 'The contact details (email and WhatsApp) come from Site settings, so do not write them here again.',
})

// ---------------------------------------------------------------- «ليه تختارنا؟»
/**
 * The marketing page that answers «ليه Thinkera؟» (17 October 2026): the learning journey in order — watch and
 * answer, practise and understand why, write and get graded, sit the unit exams again and again, never alone —
 * then the figures, who it is for (the student now, the teacher in the next phase) and a closing call.
 *
 * Every line is meant to be true with no footnote under it, so the wording carries the limits itself: «مئات
 * الأسئلة», «الأسئلة بتتغيّر», «حصتك الخاصة», no promise of a 24-hour chat. Change a claim here only after it is
 * true on the platform.
 */
export const WhyUs: GlobalConfig = {
  slug: 'whyus',
  label: { ar: 'صفحة ليه تختارنا', en: 'Why us page' },
  admin: {
    group: content,
    description: {
      ar: 'الصفحة على ‎/whyus‎. كل جملة هنا لازم تكون صح من غير تحفظ تحتها، فما تزوّدش ادعاء قبل ما يبقى شغّال على المنصة.',
      en: 'The page at /whyus. Every line must be true with no footnote under it: add a claim only once it works on the platform.',
    },
  },
  access: { read },
  fields: [
    seo(),
    txt('kicker', 'السطر الصغير فوق العنوان', 'Kicker'),
    txt('h1', 'العنوان', 'Heading', { required: true }),
    area('lead', 'الفقرة', 'Lead'),
    list('steps', 'خطوات الرحلة', 'Journey steps', [txt('label', 'الخطوة', 'Step', { required: true, localized: false })]),
    txt('cardsTitle', 'عنوان البطاقات', 'Cards heading'),
    list('cards', 'البطاقات', 'Cards', [
      txt('title', 'العنوان', 'Title', { required: true, localized: false }),
      area('line', 'الجملة الأساسية', 'Main line', { localized: false }),
      area('text', 'التفاصيل', 'Details', { localized: false }),
    ], {
      admin: {
        description: {
          ar: 'لو عدد البطاقات فردي، الأخيرة بتاخد عرض الصف كله.',
          en: 'With an odd number of cards, the last one spans the whole row.',
        },
      },
    }),
    list('figures', 'الأرقام', 'Figures', [
      txt('n', 'الرقم', 'Figure', { required: true, localized: false }),
      txt('label', 'الوصف', 'Label', { localized: false }),
    ]),
    txt('audienceTitle', 'عنوان «معمولة لمين»', 'Audience heading'),
    group('student', 'الطالب', 'Student', [
      txt('tag', 'الشارة', 'Badge'),
      txt('title', 'العنوان', 'Title'),
      area('text', 'النص', 'Text'),
    ]),
    group('teacher', 'المعلم', 'Teacher', [
      txt('tag', 'الشارة', 'Badge'),
      txt('title', 'العنوان', 'Title'),
      area('text', 'النص', 'Text'),
      list('points', 'النقاط', 'Points', [area('text', 'النقطة', 'Point', { required: true, localized: false })]),
    ]),
    txt('quotesTitle', 'عنوان الجمل', 'Lines heading'),
    list('quotes', 'جمل قصيرة', 'Short lines', [txt('text', 'الجملة', 'Line', { required: true, localized: false })]),
    txt('ctaTitle', 'عنوان الدعوة في الآخر', 'Closing call heading'),
    area('ctaLead', 'سطر الدعوة', 'Closing call line'),
    txt('ctaLabel', 'نص الزر', 'Button label'),
    href('ctaHref', false),
  ],
}
