import { useProductContext } from '@/contexts/ProductContext';
import useAuth from '@/core/hooks/useAuth';
import { getCountCart } from '@/core/utils/cart';
import { createSlug } from '@/core/utils/slug';
import whatsappUrl from '@/core/utils/whatsappUrl';
import IndoteknikLogo from '@/images/logo.png';
import Cardheader from '@/lib/cart/components/Cartheader';
import Category from '@/lib/category/components/Category';
import {
ChevronDownIcon,
DocumentCheckIcon,
HeartIcon,
} from '@heroicons/react/24/outline';
import dynamic from 'next/dynamic';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import DesktopView from '../../views/DesktopView';
import Link from '../Link/Link';
import NavbarUserDropdown from './NavbarUserDropdown';
import NextImage from 'next/image';
import style from "./style/NavbarDesktop.module.css";
const Search = dynamic(() => import('./Search'), { ssr: false });
const TopBanner = dynamic(() => import('./TopBanner'), { ssr: false });
const NavbarDesktop = () => {
const [isOpenCategory, setIsOpenCategory] = useState(false);
const auth = useAuth();
const [cartCount, setCartCount] = useState(0);
const [templateWA, setTemplateWA] = useState(null);
const [payloadWA, setPayloadWa] = useState(null);
const [urlPath, setUrlPath] = useState(null);
const router = useRouter();
const { product } = useProductContext();
useEffect(() => {
if (router.pathname === '/shop/product/[slug]') {
setPayloadWa({
name: product?.name,
manufacture: product?.manufacture.name,
url: createSlug('/shop/product/', product?.name, product?.id, true),
});
setTemplateWA('product');
setUrlPath(router.asPath);
}
}, [product, router]);
useEffect(() => {
const handleCartChange = () => {
const cart = async () => {
const listCart = await getCountCart();
setCartCount(listCart);
};
cart();
};
handleCartChange();
window.addEventListener('localStorageChange', handleCartChange);
return () => {
window.removeEventListener('localStorageChange', handleCartChange);
};
}, []);
return (