import 'package:flutter/material.dart';
import 'package:travel_mate/components/settings/policies/policies_content.dart';
import 'theme/settings_theme_content.dart';
import 'profile/profile_content.dart';

import 'package:package_info_plus/package_info_plus.dart';

class SettingsContent extends StatefulWidget {
  const SettingsContent({super.key});

  @override
  State<SettingsContent> createState() => _SettingsContentState();
}

class _SettingsContentState extends State<SettingsContent> {
  String _version = '...';

  @override
  void initState() {
    super.initState();
    _loadVersion();
  }

  Future<void> _loadVersion() async {
    final packageInfo = await PackageInfo.fromPlatform();
    if (mounted) {
      setState(() {
        _version = packageInfo.version;
      });
    }
  }

  Future<void> changePage(BuildContext context, Widget page) async {
    Navigator.push(context, MaterialPageRoute(builder: (context) => page));
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: const EdgeInsets.all(16),
      children: [
        // Section Profil intégrée
        ProfileContent(),

        const SizedBox(height: 20),

        // Autres paramètres
        Text(
          'Préférences',
          style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
            color: Colors.grey[600],
          ),
        ),
        const SizedBox(height: 8),

        ListTile(
          leading: const Icon(Icons.palette),
          title: const Text('Thème'),
          subtitle: const Text('Clair, sombre ou système'),
          trailing: const Icon(Icons.arrow_forward_ios),
          onTap: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => const SettingsThemeContent(),
              ),
            );
          },
        ),

        ListTile(
          leading: const Icon(Icons.privacy_tip),
          title: const Text('Confidentialité'),
          trailing: const Icon(Icons.arrow_forward_ios),
          onTap: () {
            changePage(context, const PoliciesContent());
          },
        ),

        const SizedBox(height: 30),
        Center(
          child: Column(
            children: [
              Text(
                'Travel Mate © 2025',
                style: TextStyle(fontSize: 16, color: Colors.grey[600]),
              ),
              const SizedBox(height: 4),
              Text(
                'Version de l\'application',
                style: TextStyle(fontSize: 16, color: Colors.grey[600]),
              ),
              const SizedBox(height: 4),
              Text(
                _version,
                style: TextStyle(fontSize: 14, color: Colors.grey[500]),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
