import 'package:flutter/material.dart';
import 'package:sigap/src/features/personalization/presentasion/pages/settings/widgets/base_detail_screen.dart';

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

  @override
  _LanguageSettingsScreenState createState() => _LanguageSettingsScreenState();
}

class _LanguageSettingsScreenState extends State<LanguageSettingsScreen> {
  String selectedLanguage = 'English (US)';

  final List<Map<String, String>> languages = [
    {'name': 'English (US)', 'code': 'en_US'},
    {'name': 'Bahasa Indonesia', 'code': 'id_ID'},
    {'name': 'Español', 'code': 'es_ES'},
    {'name': 'Français', 'code': 'fr_FR'},
    {'name': '日本語', 'code': 'ja_JP'},
    {'name': '한국어', 'code': 'ko_KR'},
  ];

  @override
  Widget build(BuildContext context) {
    return BaseDetailScreen(
      title: 'Language',
      content: ListView(
        children: [
          _buildSectionHeader('Select Language'),
          ...languages.map((lang) => _buildLanguageItem(lang['name']!)),
        ],
      ),
    );
  }

  Widget _buildSectionHeader(String title) {
    final theme = Theme.of(context);

    return Container(
      padding: const EdgeInsets.fromLTRB(20, 30, 20, 10),
      child: Text(
        title,
        style: theme.textTheme.titleMedium?.copyWith(
          fontWeight: FontWeight.w600,
        ),
      ),
    );
  }

  Widget _buildLanguageItem(String language) {
    final theme = Theme.of(context);

    return InkWell(
      onTap: () {
        setState(() {
          selectedLanguage = language;
        });
      },
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(color: theme.dividerColor.withOpacity(0.5)),
          ),
        ),
        child: Row(
          children: [
            Expanded(child: Text(language, style: theme.textTheme.bodyLarge)),
            if (language == selectedLanguage)
              Icon(Icons.check, color: theme.primaryColor),
          ],
        ),
      ),
    );
  }
}
