import React, { useState } from 'react';
import {
  View, Text, ScrollView, TouchableOpacity, StyleSheet, Linking,
} from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { useBooking } from '../context/BookingContext';
import { COLORS, FONTS, FONT_SIZE, SPACING } from '../theme';
import { MethodType } from '../types';

const METHODS: { id: MethodType; label: string; icon: string }[] = [
  { id: 'hypnosis',    label: 'Hypnosis',    icon: 'brain' },
  { id: 'emdr',        label: 'EMDR',        icon: 'eye' },
  { id: 'act',         label: 'ACT',         icon: 'compass' },
  { id: 'yager',       label: 'Yager',       icon: 'layers' },
  { id: 'mindfulness', label: 'Mindfulness', icon: 'leaf' },
  { id: 'coaching',    label: 'Coaching',    icon: 'trophy' },
];

const CONTENT: Record<MethodType, { title: string; intro: string[]; bullets: string[]; bulletHeading: string }> = {
  hypnosis: {
    title: 'Hypnosis & Hypnotherapy',
    intro: [
      'If you\'re searching for a method that fosters significant breakthroughs and tangible progress within just a few sessions, Hypnosis could be exactly what you need. Rooted in extensive scientific research, Hypnosis is a remarkably powerful approach that brings about profound, long-lasting change.',
      'What makes Hypnosis so uniquely effective is its ability to bypass the conscious, logical mind and tap into the subconscious — where the root causes of our challenges often reside. Unlike methods that only address symptoms on the surface, Hypnosis works at the core, allowing for transformative improvements and meaningful healing.',
    ],
    bulletHeading: 'Why is hypnosis so powerful?',
    bullets: [
      'Significant breakthroughs and noticeable improvement in just a few sessions.',
      'Addresses a wide range of challenges — emotional, psychological, and psychosomatic.',
      'Exceptionally effective for long-standing, chronic, and deeply rooted issues.',
      'Works at the subconscious level to uncover and resolve the root cause of the issue.',
      'You remain fully awake, aware, and in control throughout the entire process.',
    ],
  },
  emdr: {
    title: 'EMDR — Eye Movement Desensitization & Reprocessing',
    intro: [
      'EMDR is a scientifically validated psychotherapy method originally developed for trauma and PTSD. Its applications have expanded to anxiety, panic attacks, phobias, self-worth issues, and limiting beliefs.',
      'Developed by Dr. Francine Shapiro in the late 1980s, EMDR helps process and resolve distressing memories using bilateral stimulation — such as guided eye movements. Unlike talk therapy, EMDR works on a much deeper level, enabling your brain to reprocess painful memories so they lose their emotional charge.',
      'EMDR is a gentle yet powerful approach that helps your brain heal from distressing experiences. Instead of just coping with the pain, EMDR helps you process and release it, so it no longer controls your life.',
    ],
    bulletHeading: 'Why is EMDR so effective?',
    bullets: [
      'Supports the brain\'s natural healing process, resolving pain on a deeper level than talk therapy.',
      'Fast results: significant improvement often noticed after just a few sessions.',
      'Gentle process: you process memories without repeatedly reliving the distressing experience.',
      'Scientifically proven: one of the most thoroughly researched methods for treating PTSD.',
      'Highly effective for trauma, anxiety, grief, limiting beliefs, and self-worth issues.',
    ],
  },
  act: {
    title: 'Acceptance & Commitment Therapy (ACT)',
    intro: [
      'ACT helps us commit to creating a rich and meaningful life based on what truly matters, while accepting the pain that life inevitably brings. It\'s not the unpleasant emotions that make life difficult, but our constant struggle against them.',
      'Take a moment and ask yourself honestly: has fighting your negative thoughts been successful? Have all the doubts, fears, and difficult emotions simply disappeared? In most cases, the answer is no. The fight feels endless and takes enormous energy.',
      'The good news is that we can learn many tools and techniques to let go of that struggle and instead focus on what truly matters. ACT has been proven effective for anxiety, depression, trauma, addiction, stress, burnout, and much more.',
    ],
    bulletHeading: 'Key dimensions of ACT:',
    bullets: [
      'Values Clarification — exploring your core values as the guiding stars of your life.',
      'Accepting Difficult Feelings — developing skills to reduce the grip of painful thoughts.',
      'Present-Moment Awareness — focusing attention on the here and now.',
      'Psychological Flexibility — living a life based on your individual core values and goals.',
      'Committed Action — taking purposeful steps aligned with what truly matters to you.',
    ],
  },
  yager: {
    title: 'Yager Therapy (The Yager Code)',
    intro: [
      'Yager Therapy is a powerful, innovative approach designed to help resolve deep-seated emotional issues and limiting beliefs. It works by accessing the subconscious mind to address root causes — without requiring you to relive past traumas.',
      'Developed in 1972 by Prof. Dr. Edwin K. Yager at the University of San Diego, this method focuses on leveraging the mind\'s inner wisdom and ability to heal itself. During a session, we work with an aspect of your mind called the "higher intelligence" to guide the healing process.',
      'Yager Therapy is a gentle and non-invasive method, suitable for those who prefer to avoid discussing painful memories in detail. It provides rapid, effective change by reprogramming the mind at its core.',
    ],
    bulletHeading: 'Why is Yager Therapy so impactful?',
    bullets: [
      'Effective for a broad range of psychological, psychosomatic, and stress-amplified issues.',
      'Highly effective for long-standing conditions where other therapies have reached their limits.',
      'Works seamlessly online, by phone, or in person.',
      'Works for nearly everyone — including those resistant to traditional hypnosis.',
      'Supported by over 40 years of scientific research confirming high efficacy and absolute safety.',
    ],
  },
  mindfulness: {
    title: 'Mindfulness & Relaxation Techniques',
    intro: [
      'I personally find great value in practical tools that we can all use to regulate our emotions and state of being. From the very first session, you\'ll gain hands-on tools and skills that you can apply right away — not just between sessions but long after coaching is complete.',
      'These practices are intended to increase your ability to self-regulate: regulating your emotions and fears, cultivating mental stability, building unwavering trust and safety within yourself, and learning to stay grounded in the present moment.',
    ],
    bulletHeading: 'What we explore together:',
    bullets: [
      'Breath Work — your fastest nervous system regulator. Shift from overwhelm to clarity instantly.',
      'Somatic Embodiment — tuning into your body\'s wisdom to feel more grounded and at home.',
      'Mindfulness — breaking free from the cycle of rumination and living fully in the present.',
      'Self-Compassion — meeting yourself with the same kindness you offer to others.',
      'Progressive Muscle Relaxation — releasing physical tension systematically for deep rest.',
    ],
  },
  coaching: {
    title: 'Life Coaching',
    intro: [
      'All our lives come with ups and downs and unique challenges. Here and there we face situations where our own strategies and coping mechanisms just don\'t do the job. We feel stuck, tired, lost, vulnerable, or unhappy.',
      'I strongly believe that we all, at some point in our lives, need a little guidance — someone who helps us focus on what really matters, supports us in taking the next step, or just listens.',
      'I am convinced that we all have the solutions for our challenges within us, but at times we just can\'t access them. Together we can shed light on your skills, strengths, and passions — evaluating what works and finding strategies that fuel positive personal and professional growth.',
    ],
    bulletHeading: 'Challenges Life Coaching can help with:',
    bullets: [
      'Burnout, exhaustion, and lost sense of direction or purpose.',
      'Self-confidence, self-worth, and persistent imposter syndrome.',
      'Procrastination, decision paralysis, and fear of the unknown.',
      'Work-life balance and recovering a fulfilling family life.',
      'Breaking unhealthy habits and building consistent new ones.',
      'Craving deep, sustained inner calm and peace.',
    ],
  },
};

export default function MethodsScreen({ route }: any) {
  const initial: MethodType = route?.params?.selectedMethod ?? 'hypnosis';
  const [active, setActive] = useState<MethodType>(initial);
  const { openBookingModal } = useBooking();
  const openWhatsApp = () => Linking.openURL('https://wa.me/250790000000');
  const content = CONTENT[active];

  return (
    <View style={{ flex: 1, backgroundColor: COLORS.white }}>
      {/* Sticky Tab Bar */}
      <ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.tabBar} contentContainerStyle={styles.tabBarContent}>
        {METHODS.map(m => (
          <TouchableOpacity
            key={m.id}
            style={[styles.tab, active === m.id && styles.tabActive]}
            onPress={() => setActive(m.id)}
          >
            <Ionicons name={m.icon as any} size={15} color={active === m.id ? COLORS.white : COLORS.slate700} />
            <Text style={[styles.tabLabel, active === m.id && styles.tabLabelActive]}>{m.label}</Text>
          </TouchableOpacity>
        ))}
      </ScrollView>

      <ScrollView showsVerticalScrollIndicator={false}>

        {/* Content Section */}
        <View style={styles.section}>
          <Text style={styles.pageTitle}>{content.title}</Text>
          <View style={styles.divider} />
          {content.intro.map((para, i) => (
            <Text key={i} style={styles.bodyText}>{para}</Text>
          ))}
          <View style={styles.rowBtns}>
            <TouchableOpacity style={styles.btnDark} onPress={openBookingModal}>
              <Text style={styles.btnDarkText}>Book FREE Call</Text>
            </TouchableOpacity>
            <TouchableOpacity style={styles.btnOutline} onPress={openWhatsApp}>
              <Text style={styles.btnOutlineText}>WhatsApp</Text>
            </TouchableOpacity>
          </View>
        </View>

        {/* Bullets Box */}
        <View style={styles.darkSection}>
          <Text style={styles.darkSectionTitle}>{content.bulletHeading}</Text>
          {content.bullets.map((b, i) => (
            <View key={i} style={styles.bulletRow}>
              <Ionicons name="checkmark" size={16} color={COLORS.white} />
              <Text style={styles.bulletText}>{b}</Text>
            </View>
          ))}
        </View>

        {/* Certifications for Hypnosis */}
        {active === 'hypnosis' && (
          <View style={styles.section}>
            <Text style={styles.sectionHeading}>Hypnosis Certifications & Qualifications</Text>
            <View style={styles.divider} />
            {[
              'Hypnosis-Master — German Institute of Clinical Hypnosis (DIKH, Dr. Norbert Preetz)',
              'Certified Hypnotherapist — National Guild of Hypnotists (NGH, USA)',
              'Hypnosis Therapist / Hypnoanalysis — focus on regression & root-cause healing',
              'Hypnosis Coach Certification — goal setting, behavioral change & sports performance',
            ].map((cert, i) => (
              <View key={i} style={styles.certRow}>
                <Ionicons name="shield-checkmark" size={16} color={COLORS.slate800} />
                <Text style={styles.certText}>{cert}</Text>
              </View>
            ))}
          </View>
        )}

        {/* Myths/Facts for Hypnosis */}
        {active === 'hypnosis' && (
          <View style={[styles.section, { backgroundColor: COLORS.slate50, gap: SPACING.md }]}>
            <Text style={styles.sectionHeading}>What Hypnosis Is and Is NOT</Text>
            <View style={styles.divider} />
            <View style={styles.mythCard}>
              <View style={[styles.mythBadge, { backgroundColor: '#fef2f2' }]}>
                <Text style={[styles.mythBadgeText, { color: '#dc2626' }]}>Myths & Misconceptions</Text>
              </View>
              <Text style={styles.mythTitle}>What Hypnosis is NOT</Text>
              <Text style={styles.mythBody}>It is NOT a loss of control, mind control, or being put to sleep. You do NOT reveal deep secrets against your will. During a clinical session, you are fully awake, aware, and in control. You cannot be forced to do anything against your ethics or desires.</Text>
            </View>
            <View style={[styles.mythCard, { borderWidth: 2, borderColor: COLORS.slate900 }]}>
              <View style={[styles.mythBadge, { backgroundColor: '#ecfdf5' }]}>
                <Text style={[styles.mythBadgeText, { color: '#059669' }]}>Therapeutic Reality</Text>
              </View>
              <Text style={styles.mythTitle}>What Hypnosis IS</Text>
              <Text style={styles.mythBody}>It IS a state of deep mental relaxation combined with heightened focus and receptivity. A gentle, empowering collaborative process where we bypass the critical mind to directly work with your inner wisdom — re-patterning old habits and stress responses.</Text>
            </View>
          </View>
        )}

        {/* ACT Six Processes */}
        {active === 'act' && (
          <View style={[styles.section, { backgroundColor: COLORS.slate50 }]}>
            <Text style={styles.sectionHeading}>The Six Core Processes of ACT</Text>
            <View style={styles.divider} />
            {[
              { title: '1. Acceptance',          body: 'Embracing uncomfortable thoughts and feelings without fighting against them.' },
              { title: '2. Cognitive Defusion',  body: 'Distancing oneself from distressing thoughts to see them as just words, reducing their impact.' },
              { title: '3. Mindfulness',         body: 'Staying grounded in the present moment, observing without judgment.' },
              { title: '4. Self as Context',     body: 'Understanding that you are the observer of your thoughts — not defined by them.' },
              { title: '5. Values Clarification',body: 'Gaining absolute clarity on your deepest, authentic beliefs and how you want to show up in life.' },
              { title: '6. Committed Action',    body: 'Taking purposeful, concrete actions that directly align with your values.' },
            ].map((p, i) => (
              <View key={i} style={styles.processCard}>
                <Text style={styles.processTitle}>{p.title}</Text>
                <Text style={styles.processBody}>{p.body}</Text>
              </View>
            ))}
          </View>
        )}

        {/* Bottom CTA */}
        <View style={[styles.section, { backgroundColor: COLORS.slate50 }]}>
          <Text style={styles.ctaTitle}>Let's Get in Touch</Text>
          <Text style={styles.ctaBody}>Any questions or do you want to book an appointment? Write me a note and I'll get back to you shortly.</Text>
          <View style={styles.rowBtns}>
            <TouchableOpacity style={styles.btnDark} onPress={openBookingModal}>
              <Text style={styles.btnDarkText}>Book FREE Call</Text>
            </TouchableOpacity>
            <TouchableOpacity style={styles.btnOutline} onPress={openWhatsApp}>
              <Text style={styles.btnOutlineText}>WhatsApp</Text>
            </TouchableOpacity>
          </View>
        </View>

      </ScrollView>
    </View>
  );
}

const styles = StyleSheet.create({
  tabBar:           { backgroundColor: COLORS.white, borderBottomWidth: 1, borderBottomColor: COLORS.slate200, maxHeight: 56 },
  tabBarContent:    { paddingHorizontal: SPACING.md, paddingVertical: SPACING.sm, gap: SPACING.sm, alignItems: 'center' },
  tab:              { flexDirection: 'row', alignItems: 'center', gap: 6, paddingHorizontal: SPACING.md, paddingVertical: SPACING.xs + 2, borderWidth: 1, borderColor: COLORS.slate200, backgroundColor: COLORS.slate50 },
  tabActive:        { backgroundColor: COLORS.slate900, borderColor: COLORS.slate900 },
  tabLabel:         { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.xxs, color: COLORS.slate800, textTransform: 'uppercase', letterSpacing: 1 },
  tabLabelActive:   { color: COLORS.white },
  section:          { padding: SPACING.lg, paddingVertical: SPACING.xl, gap: SPACING.md },
  darkSection:      { padding: SPACING.lg, paddingVertical: SPACING.xl, gap: SPACING.md, backgroundColor: COLORS.slate900 },
  pageTitle:        { fontFamily: FONTS.heading, fontSize: FONT_SIZE.xxl, fontWeight: '900', color: COLORS.slate900, textTransform: 'uppercase', letterSpacing: -0.5, lineHeight: 34 },
  sectionHeading:   { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.base, color: COLORS.slate900, textTransform: 'uppercase', letterSpacing: 1 },
  divider:          { width: 48, height: 2, backgroundColor: COLORS.slate900 },
  bodyText:         { fontFamily: FONTS.serif, fontSize: FONT_SIZE.base, color: COLORS.slate600, lineHeight: 26 },
  darkSectionTitle: { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.lg, color: COLORS.white, textTransform: 'uppercase', letterSpacing: 1 },
  bulletRow:        { flexDirection: 'row', gap: SPACING.sm, alignItems: 'flex-start' },
  bulletText:       { flex: 1, fontFamily: FONTS.sans, fontSize: FONT_SIZE.sm, color: COLORS.slate200, lineHeight: 20 },
  certRow:          { flexDirection: 'row', gap: SPACING.sm, alignItems: 'flex-start', padding: SPACING.sm, backgroundColor: COLORS.slate50, borderWidth: 1, borderColor: COLORS.slate200 },
  certText:         { flex: 1, fontFamily: FONTS.sans, fontSize: FONT_SIZE.xs, color: COLORS.slate600, lineHeight: 18 },
  mythCard:         { backgroundColor: COLORS.white, borderWidth: 1, borderColor: COLORS.slate200, padding: SPACING.md, gap: SPACING.sm },
  mythBadge:        { alignSelf: 'flex-start', paddingHorizontal: SPACING.sm, paddingVertical: 3 },
  mythBadgeText:    { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.xxs, textTransform: 'uppercase', letterSpacing: 1 },
  mythTitle:        { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.sm, color: COLORS.slate900, textTransform: 'uppercase', letterSpacing: 1 },
  mythBody:         { fontFamily: FONTS.serif, fontSize: FONT_SIZE.xs, color: COLORS.slate500, lineHeight: 18 },
  processCard:      { backgroundColor: COLORS.white, borderWidth: 1, borderColor: COLORS.slate200, padding: SPACING.md, gap: 4 },
  processTitle:     { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.xs, color: COLORS.slate900, textTransform: 'uppercase', letterSpacing: 2 },
  processBody:      { fontFamily: FONTS.serif, fontSize: FONT_SIZE.xs, color: COLORS.slate500, lineHeight: 18 },
  ctaTitle:         { fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.lg, color: COLORS.slate900, textTransform: 'uppercase', letterSpacing: 1 },
  ctaBody:          { fontFamily: FONTS.serif, fontSize: FONT_SIZE.sm, color: COLORS.slate500, lineHeight: 20 },
  rowBtns:          { flexDirection: 'row', gap: SPACING.sm },
  btnDark:          { flex: 1, backgroundColor: COLORS.slate900, paddingVertical: SPACING.sm + 4, alignItems: 'center', justifyContent: 'center' },
  btnDarkText:      { color: COLORS.white, fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.xxs, textTransform: 'uppercase', letterSpacing: 2 },
  btnOutline:       { flex: 1, borderWidth: 1, borderColor: COLORS.slate200, paddingVertical: SPACING.sm + 4, alignItems: 'center', justifyContent: 'center' },
  btnOutlineText:   { color: COLORS.slate900, fontFamily: FONTS.sans, fontWeight: '700', fontSize: FONT_SIZE.xxs, textTransform: 'uppercase', letterSpacing: 2 },
});
