File size: 3,776 Bytes
d39feec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from 'react'

const Cart = ({ show, onHide, cart, onUpdateQuantity, onRemoveFromCart, totalPrice }) => {
  return (
    <>
      {show && <div className="cart-overlay" onClick={onHide}></div>
      
      <div className={`cart-sidebar ${show ? 'show' : ''}`}>
        <div className="d-flex flex-column h-100">
          <div className="d-flex justify-content-between align-items-center p-3 border-bottom">
            <h5 className="mb-0">
              <i className="bi bi-cart3 me-2"></i>
              Shopping Cart
            </h5>
            <button 
              className="btn btn-outline-secondary btn-sm"
              onClick={onHide}
            >
              <i className="bi bi-x-lg"></i>
            </button>
          </div>
          
          <div className="flex-grow-1 overflow-auto p-3">
            {cart.length === 0 ? (
              <div className="text-center text-muted py-5">
                <i className="bi bi-cart-x display-1"></i>
                <p className="mt-3">Your cart is empty</p>
            ) : (
              cart.map(item => (
                <div key={item.id} className="card mb-3">
                  <div className="card-body">
                    <div className="row align-items-center">
                      <div className="col-3">
                        <img 
                          src={item.image} 
                          alt={item.title}
                          className="img-fluid rounded"
                        />
                      </div>
                      
                      <div className="col-9">
                        <h6 className="card-title text-truncate">{item.title}</h6>
                        <div className="d-flex justify-content-between align-items-center">
                        <span className="fw-bold text-primary">${item.price}</span>
                        
                        <div className="d-flex align-items-center mt-2">
                          <button 
                            className="btn btn-outline-secondary btn-sm"
                            onClick={() => onUpdateQuantity(item.id, item.quantity - 1)}
                          >
                            <i className="bi bi-dash"></i>
                          </button>
                          
                          <span className="mx-3 fw-bold">{item.quantity}</span>
                          
                          <button 
                            className="btn btn-outline-secondary btn-sm"
                            onClick={() => onUpdateQuantity(item.id, item.quantity + 1)}
                          >
                            <i className="bi bi-plus"></i>
                          </button>
                          
                          <button 
                            className="btn btn-outline-danger btn-sm ms-2"
                            onClick={() => onRemoveFromCart(item.id)}
                          >
                            <i className="bi bi-trash"></i>
                          </button>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              ))
            )}
          </div>
          
          {cart.length > 0 && (
            <div className="border-top p-3">
              <div className="d-flex justify-content-between align-items-center mb-3">
                <h5 className="mb-0">Total: ${totalPrice.toFixed(2)}</h5>
              </div>
              
              <button className="btn btn-primary w-100">
                Checkout <i className="bi bi-arrow-right ms-2"></i>
              </button>
            </div>
          )}
        </div>
      </div>
    </>
  )
}

export default Cart