summaryrefslogtreecommitdiff
path: root/src-migrate/modules/cart/components/CartSummaryMobile.tsx
blob: 7a334fed643b4293c1d0a24b1a8ebce05d06dcf8 (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import style from '../styles/summary.module.css';

import React, { useState } from 'react';
import formatCurrency from '~/libs/formatCurrency';
import clsxm from '~/libs/clsxm';
import { Button, Skeleton } from '@chakra-ui/react';
import _ from 'lodash';
import { ChevronDownIcon } from '@heroicons/react/24/outline';
import BottomPopup from '@/core/components/elements/Popup/BottomPopup';
import useDevice from '@/core/hooks/useDevice';

type Props = {
  total?: number;
  discount?: number;
  subtotal?: number;
  tax?: number;
  shipping?: number;
  grandTotal?: number;
  isLoaded: boolean;
};

const CartSummaryMobile = ({
  total,
  discount,
  subtotal,
  tax,
  shipping,
  grandTotal,
  isLoaded = false,
}: Props) => {
  const [showPopup, setShowPopup] = useState(false);
  const PPN: number = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0;
  return (
    <>
      <BottomPopup
        className=' !h-[35%]'
        title='Ringkasan Pensanan'
        active={showPopup}
        close={() => setShowPopup(false)}
      >
        <div className='mt-4'>
          <div className='flex flex-col gap-y-3'>
            <Skeleton isLoaded={isLoaded} className={style.line}>
              <span className={style.label}>Total Belanja</span>
              <span className={style.value}>
                Rp {formatCurrency(subtotal || 0)}
              </span>
            </Skeleton>

            <Skeleton isLoaded={isLoaded} className={style.line}>
              <span className={style.label}>Total Diskon</span>
              <span className={clsxm(style.value, style.discount)}>
                - Rp {formatCurrency(discount || 0)}
              </span>
            </Skeleton>

            <div className={style.divider} />

            <Skeleton isLoaded={isLoaded} className={style.line}>
              <span className={style.label}>Subtotal</span>
              <span className={style.value}>
                Rp {formatCurrency(total || 0)}
              </span>
            </Skeleton>

            <Skeleton isLoaded={isLoaded} className={style.line}>
              <span className={style.label}>Tax {((PPN - 1) * 100).toFixed(0)}%</span>
              <span className={style.value}>Rp {formatCurrency(tax || 0)}</span>
            </Skeleton>

            <Skeleton isLoaded={isLoaded} className={style.line}>
              <span className={style.label}>Biaya Kirim</span>
              <span className={style.value}>
                Rp {formatCurrency(shipping || 0)}
              </span>
            </Skeleton>

            <div className={style.divider} />
            <Skeleton isLoaded={isLoaded} className={style.line}>
              <span className={clsxm(style.label, style.grandTotal)}>
                Grand Total
              </span>
              <span className={style.value}>
                Rp {formatCurrency(grandTotal || 0)}
              </span>
            </Skeleton>
          </div>
        </div>
      </BottomPopup>
      <div className='flex flex-col gap-y-3'>
        <Skeleton
          isLoaded={isLoaded}
          className={clsxm(style.line, 'flex items-center justify-between !py-2')}
        >
          {/* Left: label */}
          <span className={clsxm(style.label, style.grandTotal, 'leading-tight')}>
            Grand Total
          </span>

          {/* Right: amount + chevron */}
          <div className="flex items-center gap-2">
            <span className={clsxm(style.value, 'whitespace-nowrap tabular-nums leading-tight')}>
              Rp {formatCurrency(grandTotal || 0)}
            </span>
            <button
              onClick={() => setShowPopup(true)}
              aria-label="Expand ringkasan"
              className="md:hidden flex w-5 h-5 items-center justify-center rounded bg-gray-300 hover:bg-gray-400"
            >
              <ChevronDownIcon className="h-4 w-4 text-white" />
            </button>
          </div>
        </Skeleton>

      </div>
    </>
  );
};

export default CartSummaryMobile;