import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:krow/core/application/common/str_extensions.dart';
import 'package:krow/core/application/routing/routes.gr.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/core/presentation/widgets/icon_row_info_widget.dart';
import 'package:krow/features/invoice/data/models/invoice_model.dart';
import 'package:krow/features/invoice/domain/invoice_entity.dart';

class InvoiceListItemWidget extends StatelessWidget {
  final InvoiceListEntity item;

  const InvoiceListItemWidget({required this.item, super.key});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        context.router.push(InvoiceDetailsRoute(
          invoice: item,
        ));
      },
      child: Container(
        decoration: KwBoxDecorations.white12,
        padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
        margin: const EdgeInsets.only(bottom: 12, left: 16, right: 16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            _buildStatusRow(),
            const Gap(12),
            Text('INV-${item.id}', style: AppTextStyles.headingH1),
            const Gap(4),
            Text(item.eventName,
                style: AppTextStyles.bodyMediumReg
                    .copyWith(color: AppColors.blackGray)),
            const Gap(12),
            IconRowInfoWidget(
              icon: Assets.images.icons.profile2user.svg(),
              title: 'Count',
              value: '${item.count} persons',
            ),
            const Gap(24),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
              decoration: KwBoxDecorations.primaryLight8.copyWith(),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('Value',
                      style: AppTextStyles.bodyMediumReg
                          .copyWith(color: AppColors.blackGray)),
                  Text(
                    '\$${item.value}',
                    style: AppTextStyles.bodyMediumMed,
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Row _buildStatusRow() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          height: 48,
          width: 48,
          decoration: const BoxDecoration(
            color: AppColors.tintGreen,
            shape: BoxShape.circle,
          ),
          child: Center(
            child: Assets.images.icons.moneySend.svg(
              colorFilter: const ColorFilter.mode(
                  AppColors.statusSuccess, BlendMode.srcIn),
            ),
          ),
        ),
        Container(
            height: 28,
            padding: const EdgeInsets.symmetric(horizontal: 8),
            decoration: BoxDecoration(
              color: item.status.color,
              borderRadius: BorderRadius.circular(14),
            ),
            child: Center(
              child: Padding(
                padding: const EdgeInsets.only(bottom: 2.0),
                child: Text(
                  item.status.name.capitalize(),
                  style: AppTextStyles.bodySmallMed
                      .copyWith(color: AppColors.grayWhite),
                ),
              ),
            ))
      ],
    );
  }
}

extension on InvoiceStatus {
  Color get color {
    switch (this) {
      case InvoiceStatus.open:
        return AppColors.primaryBlue;
      case InvoiceStatus.disputed:
        return AppColors.statusWarning;
      case InvoiceStatus.resolved:
        return AppColors.statusSuccess;
      case InvoiceStatus.paid:
        return AppColors.blackGray;
      case InvoiceStatus.overdue:
        return AppColors.statusError;
      case InvoiceStatus.verified:
        return AppColors.bgColorDark;
    }
  }
}
