import 'package:flutter/material.dart';
import 'package:sigap/src/utils/constants/colors.dart';

class CustomDropdown<T> extends StatelessWidget {
  final String label;
  final T? value;
  final List<DropdownMenuItem<T>> items;
  final Function(T?) onChanged;
  final String? Function(T?)? validator;
  final String? errorText;
  final String? hintText;
  final bool isEnabled;

  const CustomDropdown({
    Key? key,
    required this.label,
    required this.items,
    required this.onChanged,
    this.value,
    this.validator,
    this.errorText,
    this.hintText,
    this.isEnabled = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(bottom: 16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // Label
          Text(
            label,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w500,
              color: TColors.textPrimary,
            ),
          ),
          const SizedBox(height: 8),
          
          // Dropdown field
          DropdownButtonFormField<T>(
            value: value,
            items: items,
            onChanged: isEnabled ? onChanged : null,
            validator: validator,
            decoration: InputDecoration(
              hintText: hintText ?? 'Select ${label.toLowerCase()}',
              errorText: errorText,
              contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(12),
                borderSide: BorderSide(color: TColors.borderPrimary),
              ),
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(12),
                borderSide: BorderSide(color: TColors.borderPrimary),
              ),
              focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(12),
                borderSide: BorderSide(color: TColors.primary, width: 2),
              ),
              errorBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(12),
                borderSide: BorderSide(color: TColors.error, width: 1),
              ),
              focusedErrorBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(12),
                borderSide: BorderSide(color: TColors.error, width: 2),
              ),
              filled: !isEnabled,
              fillColor: !isEnabled ? TColors.lightContainer : null,
            ),
            icon: Icon(Icons.arrow_drop_down, color: TColors.textSecondary),
            dropdownColor: TColors.light,
            isExpanded: true,
          ),
        ],
      ),
    );
  }
}
