
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ongbut_ntmanh/widgets/widgets_util.dart';
import '../const/app_theme.dart';
import '../const/colors.dart';
import '../const/strings_text.dart';
import '../localization/language/languages.dart';
import '../res/images/images.dart';

class CustomDropDownRoles extends StatelessWidget {
  final List<String> itemsList;
  final Function(dynamic value) onChanged;

  const CustomDropDownRoles({
    required this.itemsList,
    required this.onChanged,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(left: 5, top: 5, bottom: 5, right: 5),
      child: Container (
        height: 400,
        width: getWidth(context),
        child: ListView.builder(
          shrinkWrap: false,
          itemCount: itemsList.length,
          itemBuilder: (context, index) {
            return item(itemsList[index],context);
          },
        ),),
    );
  }

  Widget item(String roles,BuildContext context){
    return InkWell(
      onTap: (){
        onChanged(roles);
      },
      child: Container(
        margin: EdgeInsets.all(8),
        child: Column(
          children: [
            Row(
              children: [
                Image.asset(
                  icon(roles,context),
                  fit: BoxFit.cover,
                  width: 42,
                  height: 42,
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: SizedBox(
                  width: getWidth(context)*0.5-32,
                      child: NeoText(title(roles,context), textStyle: AppTheme.textStyleLexendRegular(fontSize: 18, color: AppColors.black, overFlow: false), maxLine: 2)),
                ),
              ],
            ),
            Padding(padding: EdgeInsets.all(8)),
            Divider(height: 1,)
          ],
        ),
      ),
    );
  }
  String title(String key,BuildContext context){
    if(key==StringsText.ADMIN){
      return Languages.of(context)!.admin;
    }
    if(key==StringsText.QUAN_TRI_TRUONG){
      return Languages.of(context)!.managerSchool;
    }
    if(key==StringsText.GIAM_DOC){
      return Languages.of(context)!.systemSchool;
    }
    if(key==StringsText.GIAO_VIEN){
      return Languages.of(context)!.teacher;
    }
    if(key==StringsText.KE_TOAN){
      return Languages.of(context)!.accountant;
    }
    if(key==StringsText.NHAN_SU){
      return Languages.of(context)!.employee;
    }
    if(key==StringsText.CT_HOC_VIEN){
      return Languages.of(context)!.partner;
    }
    if(key==StringsText.HOC_SINH){
      return Languages.of(context)!.student;
    }
    return Languages.of(context)!.student;
  }

  String icon(String key,BuildContext context){
    if(key==StringsText.ADMIN||key==StringsText.QUAN_TRI_TRUONG||key==StringsText.GIAM_DOC){
      return Images.acc_school;
    }

    if(key==StringsText.GIAO_VIEN){
      return Images.acc_teacher;
    }
    if(key==StringsText.KE_TOAN){
      return Images.acc_ongbut;
    }
    if(key==StringsText.NHAN_SU){
      return Images.acc_ongbut;
    }
    if(key==StringsText.CT_HOC_VIEN){
      return Images.acc_ongbut;
    }
    if(key==StringsText.HOC_SINH){
      return Images.acc_test;
    }
    return Images.acc_test;
  }
}
