import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/presentation/home/models/order_model.dart';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
import 'package:flutter/material.dart';

class SalesListOrder extends StatelessWidget {
  final OrderModel? order;
  const SalesListOrder({super.key, this.order});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 16),
      decoration: BoxDecoration(
        color: AppColors.white,
        borderRadius: BorderRadius.circular(8),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: const EdgeInsets.all(16),
            width: double.infinity,
            decoration: const BoxDecoration(
              border: Border(
                bottom: BorderSide(color: AppColors.background),
              ),
            ),
            child: Text(
              'Daftar Pembelian',
              style: TextStyle(
                color: AppColors.black,
                fontSize: 16,
                fontWeight: FontWeight.w600,
              ),
            ),
          ),
          Column(
            children: List.generate(
              order?.orderItems.length ?? 0,
              (index) => _item(order!.orderItems[index]),
            ).toList(),
          ),
        ],
      ),
    );
  }

  Padding _item(ProductQuantity product) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16)
          .copyWith(bottom: 0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            children: [
              Text(
                product.product.name ?? '',
                style: const TextStyle(
                  fontSize: 14,
                ),
              ),
              Text(
                product.product.price ?? '',
                style: const TextStyle(
                  fontSize: 14,
                ),
              ),
            ],
          ),
          Text(
            'X${product.quantity}',
            style: const TextStyle(
              fontSize: 14,
            ),
          ),
          Text(
            product.product.price ?? '',
            style: const TextStyle(
              fontSize: 14,
            ),
          ),
        ],
      ),
    );
  }
}
