// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';

import '../themes/themes.dart';

class AppDropdown extends StatelessWidget {
  final double? height;
  final double? width;
  final String? labelText;
  final String? helperText;
  final String? selectedValue;
  final List listaOpciones;
  final String? hint;
  final void Function(Object?)? onChanged;
  String? etiqueta;

  AppDropdown({
    super.key,
    this.labelText,
    this.onChanged,
    this.width,
    this.height,
    this.hint,
    this.helperText,
    this.etiqueta,
    required this.selectedValue,
    required this.listaOpciones,
  });

  double _getFontSize(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    if (screenWidth < 480) {
      return 12;
    } else if (screenWidth < 800) {
      return 15;
    }
    return 16;
  }

  @override
  Widget build(BuildContext context) {
    double fontSize = _getFontSize(context);
    TextStyle dropdownTextStyle = TextStyle(fontSize: fontSize);
    etiqueta ??= "";
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          etiqueta.toString(),
          style: TextStyle(
            fontSize: fontSize,
            fontWeight: FontWeight.bold,
          ),
        ),
        const SizedBox(
          height: 5,
        ),
        DropdownButtonFormField(
          hint: hint != null ? Text('$hint') : null,
          borderRadius: BorderRadius.circular(15),
          dropdownColor: Colors.white,
          icon: Icon(
            Icons.arrow_drop_down_circle,
            color: AppTheme.primary,
          ),
          decoration: InputDecoration(
            labelText: labelText,
            helperText: helperText,
            floatingLabelStyle: TextStyle(
              color: AppTheme.primary,
              fontSize: fontSize,
            ),
            labelStyle: TextStyle(color: Colors.grey, fontSize: fontSize),
            focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(15),
              borderSide: BorderSide(color: AppTheme.primary),
            ),
            enabledBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(15),
              borderSide: const BorderSide(color: Colors.grey),
            ),
          ),
          value: selectedValue,
          items: listaOpciones
              .map(
                (e) => DropdownMenuItem(
                  value: e,
                  child: Text(
                    e.toString().toUpperCase(),
                    style: TextStyle(fontSize: fontSize),
                  ),
                ),
              )
              .toList(),
          onChanged: onChanged,
        ),
      ],
    );
  }
}
