import 'package:flutter/material.dart';
import 'package:niogu_app/core/constants/app_color.dart';
import 'package:niogu_app/core/constants/app_font_size.dart';
import 'package:niogu_app/core/utils/currency_format.dart';
import 'package:niogu_app/core/utils/extension_format.dart';
import 'package:niogu_app/features/online_store/domain/entities/online_store.dart';
import 'package:niogu_app/features/online_store/presentation/widgets/product_thumbnail.dart';
import 'package:sizer/sizer.dart';

class ProductDetails extends StatelessWidget {
  final List<OnlineOrderItem> items;
  const ProductDetails({super.key, required this.items});

  @override
  Widget build(BuildContext context) {
    final bool isTablet = 100.w >= 600;
    return Container(
      padding: EdgeInsets.all(4.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(4.w),
        border: Border.all(color: Colors.grey.shade200),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.02),
            blurRadius: 10,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Icon(
                Icons.shopping_bag_outlined,

                size: 5.w,
                color: AppColor.primaryColor,
              ),
              SizedBox(width: 2.w),
              Text(
                "Rincian Produk",
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: (AppFontSize.medium - (isTablet ? 0 : 1.25)).sp,
                  color: Colors.black87,
                ),
              ),
            ],
          ),
          SizedBox(height: 2.h),

          ...items.map((item) {
            return Padding(
              padding: EdgeInsets.only(bottom: 2.h),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  ProductThumbnail(imagePath: item.imagePath),
                  SizedBox(width: 3.w),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          item.name,
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: isTablet
                                ? (AppFontSize.medium - 1.25).sp
                                : (AppFontSize.small - 1.25).sp,
                          ),
                        ),
                        if (item.variantName != null &&
                            item.variantName!.isNotEmpty)
                          Text(
                            item.variantName!,
                            style: TextStyle(
                              color: Colors.grey.shade700,
                              fontSize: isTablet
                                  ? (AppFontSize.medium - 1.25).sp
                                  : (AppFontSize.small - 1.25).sp,
                            ),
                          ),

                        SizedBox(height: 1.h),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  "Harga Satuan",
                                  style: TextStyle(
                                    fontSize: isTablet
                                        ? (AppFontSize.medium - 1.25).sp
                                        : (AppFontSize.small - 1.25).sp,
                                    color: Colors.grey.shade700,
                                  ),
                                ),
                                Text(
                                  CurrencyFormat.formatToIdr(
                                    item.sellingPrice,
                                    0,
                                  ),
                                  style: TextStyle(
                                    fontSize: isTablet
                                        ? (AppFontSize.medium - 1.25).sp
                                        : (AppFontSize.small - 1.25).sp,
                                    color: Colors.black87,
                                  ),
                                ),
                              ],
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Text(
                                  "Jumlah",
                                  style: TextStyle(
                                    fontSize: isTablet
                                        ? (AppFontSize.medium - 1.25).sp
                                        : (AppFontSize.small - 1.25).sp,
                                    color: Colors.grey.shade700,
                                  ),
                                ),
                                Text(
                                  "x${item.quantity.toStringWithoutTrailingZero()}",
                                  style: TextStyle(
                                    fontSize: isTablet
                                        ? (AppFontSize.medium - 1.25).sp
                                        : (AppFontSize.small - 1.25).sp,
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                              ],
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.end,
                              children: [
                                Text(
                                  "Subtotal",
                                  style: TextStyle(
                                    fontSize: isTablet
                                        ? (AppFontSize.medium - 1.25).sp
                                        : (AppFontSize.small - 1.25).sp,
                                    color: Colors.grey.shade700,
                                  ),
                                ),
                                Text(
                                  CurrencyFormat.formatToIdr(item.subtotal, 0),
                                  style: TextStyle(
                                    fontSize: isTablet
                                        ? (AppFontSize.medium - 1.25).sp
                                        : (AppFontSize.small - 1.25).sp,
                                    fontWeight: FontWeight.bold,
                                    color: AppColor.primaryColor,
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            );
          }).toList(),
        ],
      ),
    );
  }
}
