/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-10-20 14:43:25
 * @LastEditTime : 2023-05-15 15:39:24
 * @Description  : Do not edit
 */
import 'package:flutter/widgets.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class TableView extends StatelessWidget {
  const TableView({
    Key? key,
    this.title,
    this.headers,
    required this.content,
  }) : super(key: key);
  final String? title;
  final List? headers;
  final List content;
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom.column(
      crossAxisAlignment: CrossAxisAlignment.start,
      padding: EdgeInsets.symmetric(
        horizontal: 15.pt,
      ),
      children: [
        if (title != null) ...[
          Wisdom(
            padding: EdgeInsets.only(bottom: 15.pt),
            alignment: Alignment.centerLeft,
            child: WisText(
              '$title',
              size: 14.pt,
              weight: FontWeight.w600,
              color: colorScheme.primary,
            ),
          ),
        ],
        Table(
          defaultVerticalAlignment: TableCellVerticalAlignment.middle,
          children: [
            if (headers != null) ...[
              () {
                final titles = headers;
                return TableRow(
                  decoration: BoxDecoration(
                    color: Color(0xfff8f8f8),
                  ),
                  children: [
                    for (var title in titles!)
                      WisText(
                        '$title',
                        textAlign: TextAlign.left,
                        weight: FontWeight.w500,
                        size: 13.pt,
                        strutStyle: StrutStyle(leading: 1.25),
                      ),
                  ],
                );
              }(),
            ],
            for (var item in content) ...[
              TableRow(
                // decoration: BoxDecoration(
                //   color: Color(0xfff8f8f8),
                // ),
                children: [
                  if (item is Map) ...[
                    for (var value in item.values.toList()) ...[
                      WisText(
                        '$value',
                        textAlign: TextAlign.left,
                        weight: FontWeight.bold,
                        size: 13.pt,
                        strutStyle: StrutStyle(leading: 1.25),
                      ),
                    ]
                  ] else ...[
                    for (var value in item.toJson().values.toList()) ...[
                      WisText(
                        '$value',
                        textAlign: TextAlign.left,
                        weight: FontWeight.bold,
                        size: 13.pt,
                        strutStyle: StrutStyle(leading: 1.25),
                      ),
                    ]
                  ]
                ],
              ),
            ]
          ],
        )
      ],
    );
  }
}
