import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:pharmacy_mobile/blocs/language/functions/bloc_setlanguage.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';

class SettingsMenuWidget extends StatelessWidget {
  final String title;
  final String value;
  final bool? isSelection;
  final List selectionList;
  final String selectionFor;

  const SettingsMenuWidget({
    super.key,
    required this.title,
    required this.value,
    this.isSelection = false,
    this.selectionList = const [],
    this.selectionFor = '',
  });

  @override
  Widget build(BuildContext context) {
    void setNewValue(String newValue) async {
      switch (selectionFor) {
        case 'Language':
          final language = await blocSetLanguage(context, newValue);
          if (language) {
            // ignore: use_build_context_synchronously
            context.pop();
          }
          break;

        default:
          break;
      }
    }

    return Container(
      padding: const EdgeInsets.all(16),
      width: MediaQuery.of(context).size.width,
      decoration:
          BoxDecoration(color: const Color.fromRGBO(28, 17, 32, 0.678), borderRadius: BorderRadius.circular(8.0)),
      child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        TextWidget(
          text: title,
          size: 8,
        ),
        const Gap(8),
        if (isSelection!)
          Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
            const Gap(8),
            for (var item in selectionList)
              GestureDetector(
                onTap: () => setNewValue(item),
                child: Padding(
                  padding: const EdgeInsets.symmetric(vertical: 16),
                  child: TextWidget(text: item, size: 12, color: const Color.fromRGBO(255, 255, 255, 1)),
                ),
              ),
            const Gap(8),
          ])
        else
          TextWidget(
            text: value,
            size: 12,
            bold: true,
          ),
      ]),
    );
  }
}
