import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/change_language_controller.dart';

class ChangeLanguageView extends GetView<ChangeLanguageController> {
  const ChangeLanguageView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('change_language'.tr),
        centerTitle: true,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            Text(
              'select_language'.tr,
              style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 20),
            ...controller.languages
                .map((language) => _buildLanguageOption(language)),
          ],
        ),
      ),
    );
  }

  Widget _buildLanguageOption(Map<String, dynamic> language) {
    return Obx(() {
      final isSelected = controller.isCurrentLanguage(language['code']);
      return Card(
        elevation: isSelected ? 2 : 0,
        color: isSelected ? Colors.blue.shade50 : null,
        child: ListTile(
          title: Text(language['name']),
          trailing: isSelected
              ? const Icon(Icons.check_circle, color: Colors.blue)
              : null,
          onTap: () => controller.changeLanguage(
            language['code'],
            language['country'],
          ),
        ),
      );
    });
  }
}
