import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/column_title_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';

class CustomDataTable<T> extends StatelessWidget {
  final List<String> columnsTitles;
  final List<DataCell> Function(T item) cellsWidgets;
  final List<T> items;

  const CustomDataTable({
    super.key,
    required this.items,
    required this.cellsWidgets,
    required this.columnsTitles,
  });

  @override
  Widget build(BuildContext context) {
    return DataTable2(
      dividerThickness: 0.5,
      columnSpacing: 2,
      horizontalMargin: 0,
      empty: SvgPicture.asset(Assets.emptyDataTable),
      decoration: BoxDecoration(
        color: ColorsManager.circleRolesBackground,
        borderRadius: BorderRadius.circular(12),
        boxShadow: const [
          BoxShadow(
            color: ColorsManager.textGray,
            blurRadius: 12,
            offset: Offset(0, 4),
          ),
        ],
      ),
      columns: columnsTitles.asMap().entries.map((entry) {
        final index = entry.key;
        final title = entry.value;

        return DataColumn(
          label: ColumnTitleWidget(
            title: title,
            isFirst: index == 0,
            isLast: index == columnsTitles.length - 1,
          ),
        );
      }).toList(),
      rows: items.map((item) {
        return DataRow(cells: cellsWidgets(item));
      }).toList(),
    );
  }
}
