import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:tangheem/classes/colors.dart';

class CommonDropDownButton extends StatelessWidget {
  final int index;
  final String hintText;
  final String icon;
  final Color iconColor;
  final Color color;
  final bool isDropDown;
  final VoidCallback onPressed;
  final Function(int) onSelect;
  final double widthHeight;
  final List<String> list;

  CommonDropDownButton(this.index, {Key key, this.onPressed, this.isDropDown = true, this.hintText = "", this.color, this.icon, this.widthHeight, this.iconColor, this.onSelect, this.list})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      splashColor: Colors.transparent,
      highlightColor: Colors.transparent,
      onTap: onPressed,
      child: Container(
        height: 40,
        decoration: BoxDecoration(
          color: color ?? ColorConsts.primaryBlue,
          borderRadius: BorderRadius.circular(6),
        ),
        padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
        child: DropdownButtonHideUnderline(
          child: DropdownButton<int>(
            isExpanded: isDropDown,
            dropdownColor: ColorConsts.secondaryWhite,
            icon: SvgPicture.asset(
              icon ?? "assets/icons/drop_menu.svg",
              width: widthHeight ?? 10,
              height: widthHeight ?? 5,
              color: iconColor ?? ColorConsts.secondaryOrange,
            ),
            hint: Text(
              (list.isEmpty || index < 0) ? hintText : list[index],
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(fontSize: 12, color: Colors.white),
            ),
            focusColor: Colors.white,
            style: TextStyle(color: Colors.white),
            items: !isDropDown
                ? []
                : [
                    for (int i = 0; i < list.length; i++)
                      DropdownMenuItem<int>(
                        value: i,
                        child: SizedBox(
                          width: double.infinity,
                          child: Text(
                            list[i],
                            maxLines: 1,
                            textDirection: TextDirection.rtl,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(fontSize: 14, color: ColorConsts.primaryBlack),
                          ),
                        ),
                      )
                  ],
            onChanged: onSelect,
          ),
        ),
      ),
    );
  }
}
