import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/models/get_attachement_list_model.dart';

class AttachmentsFragment extends StatelessWidget {
  final List<GetAttachementList> getAttachmentList;

  AttachmentsFragment(this.getAttachmentList);

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemCount: getAttachmentList.length,
      itemBuilder: (context, index) {
        return Row(
          children: [
            SvgPicture.asset(determineFileIcon(getAttachmentList[index].fILECONTENTTYPE ?? "")),
            12.width,
            (getAttachmentList[index].fILENAME?.capitalizeFirstofEach ?? "").toText16().expanded,
          ],
        ).objectContainerView().onPress(() {});
      },
      separatorBuilder: (BuildContext context, int index) => 12.height,
    ).paddingAll(21);
  }

  String determineFileIcon(String fileContentType) {
    String icon = "";
    switch (fileContentType) {
      case "pdf":
        icon = "assets/images/pdf.svg";
        break;
      case "xls":
        icon = "assets/images/xls.svg";
        break;
      case "xlsx":
        icon = "assets/images/xls.svg";
        break;
      case "png":
        icon = "assets/images/png.svg";
        break;
      case "jpg":
        icon = "assets/images/jpg.svg";
        break;
      case "jpeg":
        icon = "assets/images/jpg.svg";
        break;
    }
    return icon;
  }
}
