import 'package:flutter/material.dart';
import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
import 'package:krow/core/presentation/widgets/shift_payment_step_widget.dart';
import 'package:krow/core/presentation/widgets/shift_total_time_spend_widget.dart';
import 'package:krow/features/shifts/data/models/staff_shift.dart';
import 'package:krow/features/shifts/domain/shift_entity.dart';
import 'package:krow/features/shifts/presentation/widgets/shift_item_canceled_widget.dart';
import 'package:krow/features/shifts/presentation/widgets/shift_item_components/shift_additional_details_widget.dart';
import 'package:krow/features/shifts/presentation/widgets/shift_item_components/shift_item_header_widget.dart';
import 'package:krow/features/shifts/presentation/widgets/shift_item_components/shift_ongoing_counter_widget.dart';
import 'package:krow/features/shifts/presentation/widgets/shift_item_components/shift_place_and_time_widget.dart';
import 'package:krow/features/shifts/presentation/widgets/shift_item_components/shift_tags_widget.dart';

class ShiftItemWidget extends StatelessWidget {
  final ShiftEntity viewModel;
  final bool isDetailsMode;
  final VoidCallback? onPressed;
  final double bottomPadding;

  const ShiftItemWidget(this.viewModel,
      {this.bottomPadding = 0,
      this.onPressed,
      this.isDetailsMode = false,
      super.key});

  @override
  Widget build(BuildContext context) {
    var showPlaceAndTime = !isDetailsMode &&
        (viewModel.status == EventShiftRoleStaffStatus.assigned ||
            viewModel.status == EventShiftRoleStaffStatus.confirmed);

    var showTags =
        isDetailsMode || viewModel.status == EventShiftRoleStaffStatus.assigned;

    var showOngoingCounter =
        !isDetailsMode && viewModel.status == EventShiftRoleStaffStatus.ongoing;

    var showTotalTimeSpend = !isDetailsMode &&
        viewModel.status == EventShiftRoleStaffStatus.completed;

    var showAdditionalDetails =
        isDetailsMode || viewModel.status == EventShiftRoleStaffStatus.ongoing;

    var canceled =
        viewModel.status == EventShiftRoleStaffStatus.canceledByStaff ||
            viewModel.status == EventShiftRoleStaffStatus.canceledByBusiness ||
            viewModel.status == EventShiftRoleStaffStatus.canceledByAdmin;


    return GestureDetector(
      onTap: canceled?null:onPressed,
      child: Container(
        decoration: KwBoxDecorations.primaryLight12,
        margin: EdgeInsets.only(bottom: bottomPadding, left: 16, right: 16),
        padding:
            EdgeInsets.only(top: 24, bottom: showAdditionalDetails ? 0 : 24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ShiftItemHeaderWidget(viewModel),
            if (showPlaceAndTime) ShiftPlaceAndTimeWidget(viewModel),
            if (showTags)
              ShiftTagsWidget(viewModel, scrollable: !isDetailsMode),
            if (showOngoingCounter)
              ShiftOngoingCounterWidget(viewModel: viewModel),
            if (showTotalTimeSpend)
              ShiftTotalTimeSpendWidget(
                startTime: viewModel.clockIn?? DateTime.now(),
                endTime: viewModel.clockOut?? viewModel.clockIn??DateTime.now(),
                totalBreakTime: viewModel.totalBreakTime ?? 0,
              ),
            if (showTotalTimeSpend)
              const ShiftPaymentStepWidget(
                currentIndex: 1,
              ),
            if (showAdditionalDetails)
              ShiftAdditionalDetails(viewModel: viewModel),
            if (canceled)
              ShiftItemCanceledWidget(
                  reason: viewModel.cancellationReason,
                  canceledByUser: viewModel.status ==
                      EventShiftRoleStaffStatus.canceledByStaff),
          ],
        ),
      ),
    );
  }
}
