import 'package:animated_custom_dropdown/custom_dropdown.dart';
import 'package:flutter/material.dart';
import 'package:frontend_eccp_mobile/app/core/constants/constants.dart';

class AppDropdown<T> extends StatelessWidget {
  const AppDropdown({
    required this.items,
    required this.onChanged,
    super.key,
    this.value,
    this.title,
    this.hint = 'Select',
    this.showTitle = true,
    this.isRequired = false,
    this.isValid = true,
    this.informationValid = '',
    this.bgColor = const Color(0xFFF9FAFB),
    this.borderColor = const Color(0xFFE5E7EB),
    this.radius = AppSizes.s16,
  });

  final List<T> items;
  final T? value;
  final ValueChanged<T?> onChanged;

  final String? title;
  final String hint;
  final bool showTitle;
  final bool isRequired;
  final bool isValid;
  final String informationValid;

  final Color bgColor;
  final Color borderColor;
  final double radius;

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        if (showTitle && title != null)
          Padding(
            padding: const EdgeInsets.only(bottom: AppSizes.s12),
            child: Text(
              title!,
              style: AppTextStyles.label,
            ),
          ),
        CustomDropdown<T>(
          items: items,
          initialItem: value,
          onChanged: onChanged,
          hintText: hint,
          overlayHeight: 240,
          decoration: CustomDropdownDecoration(
            closedBorderRadius: BorderRadius.circular(radius),
            closedFillColor: bgColor,
            hintStyle: AppTextStyles.body,
          ),
        ),
      ],
    );
  }
}
