From eb4ae7be05ed97bd02b7f3e9cc56393f435188e2 Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 14 Jun 2023 13:22:20 +0700
Subject: layout promotion program di detail product dan layout modal popup

---
 .../components/elements/CountDown/CountDown2.jsx   | 51 ++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 src/core/components/elements/CountDown/CountDown2.jsx

(limited to 'src/core/components/elements/CountDown/CountDown2.jsx')

diff --git a/src/core/components/elements/CountDown/CountDown2.jsx b/src/core/components/elements/CountDown/CountDown2.jsx
new file mode 100644
index 00000000..61503d17
--- /dev/null
+++ b/src/core/components/elements/CountDown/CountDown2.jsx
@@ -0,0 +1,51 @@
+import { useEffect, useState } from 'react'
+
+const CountDown2 = ({ initialTime }) => {
+  const hours = Math.floor(initialTime / 3600)
+  const minutes = Math.floor((initialTime % 3600) / 60)
+  const seconds = initialTime % 60
+
+  const [timeLeft, setTimeLeft] = useState({
+    hour: hours,
+    minute: minutes,
+    second: seconds
+  })
+
+  useEffect(() => {
+    const timer = setInterval(() => {
+      const totalSeconds = timeLeft.hour * 3600 + timeLeft.minute * 60 + timeLeft.second
+      const secondsLeft = totalSeconds - 1
+      if (secondsLeft < 0) {
+        clearInterval(timer)
+      } else {
+        const hours = Math.floor(secondsLeft / 3600)
+        const minutes = Math.floor((secondsLeft % 3600) / 60)
+        const seconds = secondsLeft % 60
+        setTimeLeft({ hour: hours, minute: minutes, second: seconds })
+      }
+    }, 1000)
+    return () => clearInterval(timer)
+  }, [timeLeft])
+
+  return (
+    <div className='flex justify-between gap-x-2'>
+      <div className='flex flex-col items-center'>
+        <span className='bg-red-200 border border-red-500 text-black font-sm w-10 h-8 flex items-center justify-center rounded'>
+          {timeLeft.hour.toString().padStart(2, '0')}
+        </span>
+      </div>
+      <div className='flex flex-col items-center'>
+        <span className='bg-red-200 border border-red-500 text-black  font-sm w-10 h-8 flex items-center justify-center rounded'>
+          {timeLeft.minute.toString().padStart(2, '0')}
+        </span>
+      </div>
+      <div className='flex flex-col items-center'>
+        <span className='bg-red-200 border border-red-500 text-black font-sm w-10 h-8 flex items-center justify-center rounded'>
+          {timeLeft.second.toString().padStart(2, '0')}
+        </span>
+      </div>
+    </div>
+  )
+}
+
+export default CountDown2
-- 
cgit v1.2.3

