import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/presentation/gen/assets.gen.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 ShiftRatingWidget extends StatelessWidget {
  final ShiftEntity viewModel;

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

  final double maxRating = 5.0; // Maximum rating, e.g., 5

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(12.0),
      margin: const EdgeInsets.only(left: 16, right: 16, top: 8),
      decoration: KwBoxDecorations.primaryLight12,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'clients_rate'.tr().toUpperCase(),
            style: AppTextStyles.captionReg
                .copyWith(color: AppColors.blackCaptionText),
          ),
          const Gap(4),
          Center(
            child: Text(viewModel.rating?.rating.toStringAsFixed(1) ?? '0.0',
                style: AppTextStyles.headingH0),
          ),
          const Gap(4),
          _buildRating(viewModel.rating?.rating ?? 0),
        ],
      ),
    );
  }

  _buildRating(double rating) {
    List<Widget> stars = [];
    for (int i = 1; i <= maxRating; i++) {
      if (i <= rating) {
        stars.add(Assets.images.icons.ratingStar.star.svg());
      } else if (i - rating < 1) {
        stars.add(Assets.images.icons.ratingStar.starHalf.svg());
      } else {
        stars.add(Assets.images.icons.ratingStar.starEmpty.svg());
      }
    }

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [const Gap(28), ...stars, const Gap(28)],
    );
  }
}
