import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.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/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/itg_forms_models/fields_model.dart';
import 'package:mohem_flutter_app/widgets/item_detail_view_widget.dart';

class RequestDetailFragment extends StatelessWidget {
  List<Fields> fields;

  RequestDetailFragment({Key? key, this.fields = const <Fields>[]}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> uiList = [detailView()];
    return Container(
      width: double.infinity,
      height: double.infinity,
      child: fields.isEmpty
          ? LocaleKeys.noDataAvailable.tr().toText16().center
          : ListView(
              padding: const EdgeInsets.all(21),
              children: uiList,
            ),
    );
  }

  Widget detailView() {
    return ListView.separated(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemBuilder: (cxt, index) {
              if (fields[index].value == null) {
                return ItemDetailView(fields[index].title!, fields[index].multipleValue?.join(", ") ?? "");
              }
              return ItemDetailView(fields[index].title!, fields[index].value ?? "");
            },
            separatorBuilder: (cxt, index) => 4.height,
            itemCount: fields.length)
        .objectContainerView();
  }
}
