import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:marking_app/common/model/report/detail_base_info.dart';

class OverallLevelTable extends StatelessWidget {
  final Sheets? tableList;
  final bool? hasPad;
  const OverallLevelTable(this.tableList,{Key? key,this.hasPad = true}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return  Padding(
      padding: EdgeInsets.only(left: hasPad == true?14.r:0,right: hasPad == true?14.r:0),
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Table(
            defaultVerticalAlignment: TableCellVerticalAlignment.middle,

            defaultColumnWidth: tableList!.headData.length<7?FixedColumnWidth((MediaQuery.of(context).size.width - 28.r) / tableList!.headData.length):IntrinsicColumnWidth(),
            // defaultColumnWidth: IntrinsicColumnWidth(),
            border: TableBorder(horizontalInside: BorderSide(width: 1, color: Color(0xFFE0E5FF), style: BorderStyle.solid),
                bottom: BorderSide(width: 1, color: Color(0xFFE0E5FF), style: BorderStyle.solid),
                verticalInside: BorderSide(width: 1, color: Color(0xFFE0E5FF), style: BorderStyle.solid))

            /*TableBorder.symmetric(
              inside: BorderSide(width: 1, color: Color(0xFFE0E5FF)),
              // outside: BorderSide.none,
              outside: hasPad == true?BorderSide.none:BorderSide(width: 1, color: Color(0xFFE0E5FF)),
            )*/,
            // borderRadius: BorderRadius.circular(5.r),
            children: List.generate(tableList!.bodyData.length + 1, (bodyIndex) {
              var bodyItem ;
              if(bodyIndex > 0){
                bodyItem = tableList!.bodyData[bodyIndex - 1];
              }
              return bodyIndex == 0? TableRow(
                  decoration: BoxDecoration(
                    color: Color(0xFFF0F3FF),
                  ),
                  children:List.generate(tableList!.headData.length, (index) {
                    var item = tableList!.headData[index];
                    return Center(
                      child: Container(
                        padding: EdgeInsets.symmetric(vertical: 6.r,horizontal: 10.r),
                        child: Text(
                          item.rowData[0][0],
                          style: TextStyle(
                              fontSize: 12.sp, color: Color(0xFF505767)),
                        ),
                      ),
                    );
                  })
              ):TableRow(
                  decoration: BoxDecoration(
                    color: Colors.white,
                  ),
                  children: List.generate(tableList!.headData.length, (cell){
                    return Center(
                      child: Container(
                        padding: EdgeInsets.symmetric(vertical: 6.r,horizontal: 5.r),
                        child: cell == 0?Text(
                          bodyItem[cell].toString(),
                          style: TextStyle(
                              fontSize: 12.sp,
                              color: Color(0xFF262626)),
                        ):HtmlWidget(bodyItem[cell].toString(),textStyle: TextStyle(fontSize: 12.sp,color:  Color(0xFF262626)),),
                      ),
                    );
                  })
              );
            })
        ),
      ),
    );
  }
}
