From a59ed6e73a599a82d6ef248c57ad29f2ab9cb15d Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 29 Jul 2024 15:23:01 +0700
Subject: <iman> Merge branch 'Feature/category-management' into development

---
 src/lib/product/components/LobSectionCategory.jsx | 82 +++++++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 src/lib/product/components/LobSectionCategory.jsx

(limited to 'src/lib/product/components/LobSectionCategory.jsx')

diff --git a/src/lib/product/components/LobSectionCategory.jsx b/src/lib/product/components/LobSectionCategory.jsx
new file mode 100644
index 00000000..34a09e46
--- /dev/null
+++ b/src/lib/product/components/LobSectionCategory.jsx
@@ -0,0 +1,82 @@
+import Image from "next/image";
+import Link from 'next/link';
+import { createSlug } from '@/core/utils/slug';
+import useDevice from '@/core/hooks/useDevice';
+import { Swiper, SwiperSlide } from 'swiper/react';
+import 'swiper/css';
+import { useQuery } from 'react-query';
+import { useRouter } from 'next/router';
+import {
+    ChevronDownIcon,
+    ChevronUpIcon, // Import ChevronUpIcon for toggling
+    DocumentCheckIcon,
+    HeartIcon,
+} from '@heroicons/react/24/outline';
+import { useState } from 'react'; // Import useState
+import { getIdFromSlug } from '@/core/utils/slug'
+
+const LobSectionCategory = ({ categories }) => {
+    const { isDesktop, isMobile } = useDevice();
+    const [isOpenCategory, setIsOpenCategory] = useState(false); // State to manage category visibility
+
+    const handleToggleCategories = () => {
+        setIsOpenCategory(!isOpenCategory);
+    };
+    console.log("categories",categories[0]?.categoryIds)
+
+    const displayedCategories = categories[0]?.categoryIds;
+
+    return (
+        <section>
+            {isDesktop && (
+                <div className="group/item grid grid-flow-col gap-y-2 gap-x-4 w-full h-full">
+                    {displayedCategories?.map((category) => (
+                        <Link
+                        href={createSlug('/shop/category/', category?.name, category?.id)}
+                        key={category?.id}
+                        passHref
+                        className="block hover:scale-105 transition-transform duration-300 bg-cover bg-center h-[144px]"
+                        style={{
+                          backgroundImage: `url('${category?.image ? category?.image : 'https://erp.indoteknik.com/web/image?model=x_banner.banner&id=5&field=x_banner_image&unique=09202023100557'}')`,
+                        }}
+                      >
+                      </Link>
+                    ))}
+                </div>
+            )}
+
+            {isMobile && (
+                <div className="py-4">
+                    <Swiper slidesPerView={1.2} spaceBetween={10}>
+                        {displayedCategories?.map((category) => (
+                            <SwiperSlide key={category?.id}>
+                                <Link
+                                    href={createSlug('/shop/category/', category?.name, category?.id)}
+                                    key={category?.id}
+                                    passHref
+                                    className="block  bg-cover bg-center h-[144px]"
+                                    style={{
+                                    backgroundImage: `url('${category?.image ? category?.image : 'https://erp.indoteknik.com/web/image?model=x_banner.banner&id=5&field=x_banner_image&unique=09202023100557'}')`,
+                                    }}
+                                >
+                                </Link>
+                            </SwiperSlide>
+                        ))}
+                    </Swiper>
+                    {categories.length > 10 && (
+                        <div className="w-full flex justify-end mt-4">
+                            <button
+                                onClick={handleToggleCategories}
+                                className="flex justify-end mt-4 bg-red-500 text-white text-sm px-4 py-2 rounded"
+                            >
+                                {isOpenCategory ? 'Sembunyikan Semua' : 'Lihat Semua'}
+                            </button>
+                        </div>
+                    )}
+                </div>
+            )}
+        </section>
+    )
+}
+
+export default LobSectionCategory
-- 
cgit v1.2.3

