import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/features/shifts/domain/shift_entity.dart';

class ShiftInfoPlaningDurationWidget extends StatelessWidget {
  final ShiftEntity viewModel;

  const ShiftInfoPlaningDurationWidget({super.key, required this.viewModel});

  @override
  Widget build(BuildContext context) {
    var formattedDuration =
        _format(viewModel.endDate.difference(viewModel.startDate).inMinutes);
    var formattedBreak = _format(viewModel.planingBreakTime!);
    return Expanded(
      child: Container(
        padding: const EdgeInsets.all(12),
        decoration: KwBoxDecorations.primaryLight12,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('duration'.tr().toUpperCase(),
                style: AppTextStyles.captionReg
                    .copyWith(color: AppColors.blackCaptionText)),
            const Gap(16),
            Text(formattedDuration, style: AppTextStyles.headingH3),
            const Gap(6),
            Text('shift_duration'.tr(),
                style: AppTextStyles.bodySmallReg
                    .copyWith(color: AppColors.blackGray)),
            const Gap(12),
            Text(formattedBreak, style: AppTextStyles.headingH3),
            const Gap(6),
            Text('break_duration'.tr(),
                style: AppTextStyles.bodySmallReg
                    .copyWith(color: AppColors.blackGray)),
          ],
        ),
      ),
    );
  }

  String _format(int? duration) {
    if (duration == null) return '0 hours';
    var hours = duration ~/ 60;
    var minutes = duration % 60;
    var hoursStr = 'hours_1'.tr(namedArgs: {'hours':hours.toString(),'plural':hours == 1 ? '' : 's'});
    return minutes == 0 ? hoursStr : 'hours_minutes'.tr(namedArgs: {'hours':hours.toString(),'minutes':minutes.toString()});
  }
}
