import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/widgets/ui_kit/dialogs/kw_dialog.dart';
import 'package:krow/features/shifts/domain/shift_entity.dart';
import 'package:krow/features/shifts/domain/shifts_repository.dart';
import 'package:krow/features/shifts/presentation/dialogs/complete_dialog/shift_complete_dialog.dart';

class ShiftCompleterService {
  Future<void> startCompleteProcess(BuildContext context, ShiftEntity shift,
      {required Null Function() onComplete, bool canSkip = true}) async {

    var result = await ShiftCompleteDialog.showCustomDialog(
        context,
        canSkip,
        shift.eventName,
        shift.clockIn ?? DateTime.now(),
        shift.planingBreakTime ?? 30);

    if (result != null) {
      if(!kDebugMode)
      await getIt<ShiftsRepository>()
          .completeShift(shift, result['details'], !canSkip);
      if (result['result'] == true) {
        await KwDialog.show(
            context: context,
            icon: Assets.images.icons.medalStar,
            state: KwDialogState.positive,
            title: 'Congratulations, Shift Completed!',
            message:
                'Your break has been logged and added to your timeline. Keep up the good work!',
            primaryButtonLabel: 'Back to Shift');
      } else {
        await KwDialog.show(
            context: context,
            icon: Assets.images.icons.alertTriangle,
            state: KwDialogState.negative,
            title: 'Your Selection is under review',
            message:
                'Labor Code § 512 requires California employers to give unpaid lunch breaks to non-exempt employees. Lunch breaks must be uninterrupted. Employers cannot require employees to do any work while on their lunch breaks. They also cannot discourage employees from taking one. However, the employer and employee can agree to waive the meal break if the worker’s shift is less than 6 hours.',
            child: const Text(
              'Once resolved you will be notify.\nNo further Action',
              textAlign: TextAlign.center,
              style: AppTextStyles.bodyMediumMed,
            ),
            primaryButtonLabel: 'Continue');
      }
    }
  }
}
