'use client'

import { motion } from 'framer-motion'
import {
  User,
  CreditCard,
  Bell,
  HelpCircle,
  FileText,
  LogOut,
  ChevronRight,
  ReceiptText,
  ArrowDownLeft,
  CalendarDays,
} from 'lucide-react'
import PageTransition, { StaggerContainer, StaggerItem } from '@/components/PageTransition'
import { formatPrice } from '@/lib/utils'

const MOCK_USER = {
  initials: 'JD',
  name: 'Jean Dupont',
  email: 'jean.dupont@email.com',
  totalReservations: 4,
  totalSaved: 6000, // cents
  seniority: '3 mois',
}

interface MenuItem {
  icon: React.ElementType
  label: string
  danger?: boolean
  onClick?: () => void
}

const menuSections: MenuItem[][] = [
  [
    { icon: User, label: 'Mes informations' },
    { icon: CreditCard, label: 'Moyens de paiement' },
    { icon: Bell, label: 'Notifications' },
  ],
  [
    { icon: HelpCircle, label: 'Aide et support' },
    { icon: FileText, label: "Conditions d'utilisation" },
  ],
  [
    { icon: LogOut, label: 'Se déconnecter', danger: true },
  ],
]

export default function ProfilPage() {
  return (
    <PageTransition>
      <div className="max-w-2xl mx-auto px-4 py-6 space-y-5">

        {/* Header */}
        <h1 className="text-2xl font-bold text-gray-900">Profil</h1>

        {/* Avatar + name */}
        <motion.div
          initial={{ opacity: 0, y: 12 }}
          animate={{ opacity: 1, y: 0 }}
          transition={{ delay: 0.05 }}
          className="bg-white rounded-2xl p-5 shadow-sm border border-gray-100 flex items-center gap-4"
        >
          <div
            className="w-16 h-16 rounded-full flex items-center justify-center text-white text-xl font-bold flex-shrink-0 shadow-md"
            style={{ background: 'linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%)' }}
          >
            {MOCK_USER.initials}
          </div>
          <div>
            <p className="text-lg font-bold text-gray-900">{MOCK_USER.name}</p>
            <p className="text-sm text-gray-500">{MOCK_USER.email}</p>
          </div>
        </motion.div>

        {/* Quick stats */}
        <div className="grid grid-cols-3 gap-3">
          {[
            {
              icon: ReceiptText,
              label: 'Réservations',
              value: String(MOCK_USER.totalReservations),
              color: 'bg-indigo-100 text-indigo-600',
            },
            {
              icon: ArrowDownLeft,
              label: 'Économies',
              value: formatPrice(MOCK_USER.totalSaved),
              color: 'bg-green-100 text-green-600',
            },
            {
              icon: CalendarDays,
              label: 'Ancienneté',
              value: MOCK_USER.seniority,
              color: 'bg-orange-100 text-orange-600',
            },
          ].map(({ icon: Icon, label, value, color }, i) => (
            <motion.div
              key={label}
              initial={{ opacity: 0, y: 12 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ delay: 0.08 + i * 0.05 }}
              className="bg-white rounded-2xl p-3 shadow-sm border border-gray-100 flex flex-col items-center text-center gap-1.5"
            >
              <div className={`w-8 h-8 rounded-xl flex items-center justify-center ${color}`}>
                <Icon className="w-4 h-4" />
              </div>
              <p className="text-sm font-bold text-gray-900 leading-tight">{value}</p>
              <p className="text-xs text-gray-500">{label}</p>
            </motion.div>
          ))}
        </div>

        {/* Menu sections */}
        <StaggerContainer className="space-y-3">
          {menuSections.map((section, sIdx) => (
            <StaggerItem key={sIdx}>
              <div className="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
                {section.map(({ icon: Icon, label, danger, onClick }, idx) => (
                  <div key={label}>
                    {idx > 0 && <div className="mx-4 border-t border-gray-50" />}
                    <motion.button
                      whileTap={{ scale: 0.99 }}
                      onClick={onClick}
                      className="w-full flex items-center justify-between px-4 py-3.5 text-left hover:bg-gray-50 transition-colors"
                    >
                      <div className="flex items-center gap-3">
                        <div
                          className={`w-8 h-8 rounded-xl flex items-center justify-center ${
                            danger
                              ? 'bg-red-100'
                              : 'bg-gray-100'
                          }`}
                        >
                          <Icon
                            className={`w-4 h-4 ${danger ? 'text-red-500' : 'text-gray-500'}`}
                          />
                        </div>
                        <span
                          className={`text-sm font-medium ${
                            danger ? 'text-red-500' : 'text-gray-800'
                          }`}
                        >
                          {label}
                        </span>
                      </div>
                      <ChevronRight className="w-4 h-4 text-gray-300" />
                    </motion.button>
                  </div>
                ))}
              </div>
            </StaggerItem>
          ))}
        </StaggerContainer>

        {/* Version */}
        <motion.p
          initial={{ opacity: 0 }}
          animate={{ opacity: 1 }}
          transition={{ delay: 0.5 }}
          className="text-center text-xs text-gray-300 pb-4"
        >
          SmartAccès v1.0.0
        </motion.p>

      </div>
    </PageTransition>
  )
}
