function OrderItem({ order }) {
  let quantity = 0;
  let sum = 0;

  for (const product of order.products) {
    quantity += product.quantity;
    sum += product.price * product.quantity;
  }

  const date = new Date(order.date).toLocaleDateString('pl-PL', {
    day: '2-digit',
    month: 'short',
    year: 'numeric',
  });

  return (
    <article>
      <h2>
        Liczba sztuk {quantity}, {date}
      </h2>
      <p>{sum.toFixed(2)} zł</p>
    </article>
  );
}

export default OrderItem;
