import 'package:flutter/material.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';

class ShiftTotalTimeSpendWidget extends StatelessWidget {
  final DateTime startTime;
  final DateTime endTime;
  final int totalBreakTime;

  const ShiftTotalTimeSpendWidget({
    super.key,
    required this.startTime,
    required this.endTime,
    required this.totalBreakTime,
  });

  @override
  Widget build(BuildContext context) {
    final totalTimeFormatted = _formatDuration(endTime.difference(startTime));
    final breakTimeFormatted =
        _formatDuration(Duration(seconds: totalBreakTime));
    return Container(
      padding: const EdgeInsets.all(12),
      margin: const EdgeInsets.only(top: 24, left: 20, right: 20),
      decoration: BoxDecoration(
        color: AppColors.graySecondaryFrame,
        borderRadius: BorderRadius.circular(8),
        border: Border.all(color: AppColors.grayStroke),
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                'Total Hours',
                style: AppTextStyles.bodyLargeReg
                    .copyWith(color: AppColors.blackGray, height: 1),
              ),
              Text(
                totalTimeFormatted,
                style: AppTextStyles.bodyLargeReg.copyWith(height: 1),
              ),
            ],
          ),
          Container(
              margin: const EdgeInsets.symmetric(vertical: 12),
              width: 160,
              height: 1,
              color: AppColors.grayTintStroke),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                'Break Hours',
                style: AppTextStyles.bodyLargeReg
                    .copyWith(color: AppColors.blackGray, height: 1),
              ),
              Text(
                breakTimeFormatted,
                style: AppTextStyles.bodyLargeReg.copyWith(height: 1),
              ),
            ],
          )
        ],
      ),
    );
  }

  String _formatDuration(Duration duration) {
    return duration.toString().split('.').first.padLeft(8, '0');
  }
}
