import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:intl/intl.dart';
import 'package:krow/core/application/common/date_time_extension.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';
import 'package:krow/core/presentation/widgets/kw_time_slot.dart';
import 'package:krow/features/shifts/domain/blocs/complete_dialog/shift_complete_dialog_bloc.dart';
import 'package:krow/features/shifts/domain/blocs/complete_dialog/shift_complete_dialog_event.dart';
import 'package:krow/features/shifts/domain/blocs/complete_dialog/shift_complete_dialog_state.dart';

class BreakTimePicker extends StatelessWidget {
  final CompleteDialogState state;

  const BreakTimePicker({super.key, required this.state});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Expanded(
              child: KwTimeSlotInput(
                label: 'Break Start Time',
                initialValue: DateFormat('H:mm').parse(state.startTime),
                onChange: (v) => context.read<CompleteDialogBloc>().add(
                      ChangeStartTime(v),
                    ),
              ),
            ),
            const Gap(12),
            Expanded(
              child: KwTimeSlotInput(
                editable: false,
                label: 'Break End Time',
                initialValue: DateFormat('H:mm').parse(state.endTime),
                onChange: (v) {},
              ),
            ),
          ],
        ),
        if (state.breakTimeInputError != null)
          Padding(
            padding: const EdgeInsets.only(top: 8, left: 16),
            child: Text(
              state.breakTimeInputError!,
              style: AppTextStyles.bodyTinyReg
                  .copyWith(color: AppColors.statusError),
            ),
          ),
      ],
    );
  }
}
