summaryrefslogtreecommitdiff
path: root/src-migrate/modules/promo/components/HeroDiskon.tsx
blob: 6d38c7630e45b4ea7edbb21b111dcc24d4fc90ca (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import 'swiper/css';

import Image from 'next/image';
import { useEffect, useMemo } from 'react';
import { useQuery } from 'react-query';
import { Swiper, SwiperProps, SwiperSlide }  from 'swiper/react';

import { getBanner } from '~/services/banner';
import style from '../styles/hero.module.css';
import 'swiper/css/navigation';
import  { Autoplay, Navigation, Pagination } from 'swiper';

const swiperBanner: SwiperProps = {
  modules:[Navigation, Pagination, Autoplay],
  autoplay: {
    delay: 6000,
    disableOnInteraction: false
  },
  loop: true,
  className: 'h-[400px] w-full',
  slidesPerView: 1,
  spaceBetween: 10,
  navigation:true,
}
const swiperBanner2: SwiperProps = {
  modules: [Pagination, Autoplay],
  autoplay: {
    delay: 5000,
  },
  loop: true,
  className: 'h-[400px] w-full',
  slidesPerView: 1,
  spaceBetween: 10,
}

const Hero = () => {
  const bannerQuery = useQuery({
    queryKey: ['banner.all-promo'],
    queryFn: () => getBanner({ type: 'banner-promotion' })
  })

  const banners = useMemo(() => bannerQuery.data || [], [bannerQuery.data]);

  useEffect(() => {
    if (banners.length > 1) {
      swiperBanner.slidesPerView = 1;
      swiperBanner.loop = true;
    }
  }, [banners]);

  return (
    
    <div className="grid grid-cols-3 gap-4">
        <div className="row-span-2 h-[446px] flex items-center ">
            <Swiper {...swiperBanner}>
            {banners.map((banner, index) => (
                <SwiperSlide key={index}>
                <Image
                    src={banner.image}
                    alt={banner.name}
                    width={666}
                    height={480}
                    className='w-[446px]  h-[446px] object-fill object-center rounded-2xl'
                />
                </SwiperSlide>
            ))}
            </Swiper>
        </div>
        <div className="w-[400px] h-[217px] ">
        <Swiper {...swiperBanner2}>
          {banners.map((banner, index) => (
            <SwiperSlide key={index}>
              <Image
                src={banner.image}
                alt={banner.name}
                width={666}
                height={450}
                className='w-[400px] h-[217px] object-cover object-center rounded-2xl '
              />
            </SwiperSlide>
          ))}
        </Swiper>
        </div>
        <div className="w-[400px] h-[217px]">
        <Swiper {...swiperBanner2}>
          {banners.map((banner, index) => (
            <SwiperSlide key={index}>
              <Image
                src={banner.image}
                alt={banner.name}
                width={666}
                height={450}
                className='w-[400px] h-[217px] object-cover object-center rounded-2xl'
              />
            </SwiperSlide>
          ))}
        </Swiper>
        </div>
        <div className="w-[400px] h-[217px]">
            <Swiper {...swiperBanner2}>
          {banners.map((banner, index) => (
            <SwiperSlide key={index}>
              <Image
                src={banner.image}
                alt={banner.name}
                width={666}
                height={450}
                className='w-[400px] h-[217px] object-cover object-center rounded-2xl'
              />
            </SwiperSlide>
          ))}
        </Swiper>
        </div>
        <div className="w-[400px] h-[217px]">
        <Swiper {...swiperBanner2}>
          {banners.map((banner, index) => (
            <SwiperSlide key={index}>
              <Image
                src={banner.image}
                alt={banner.name}
                width={666}
                height={450}
                className='w-[400px] h-[217px] object-cover object-center rounded-2xl'
              />
            </SwiperSlide>
          ))}
        </Swiper>
        </div>
        
    </div>
  
    
    
  )
}

export default Hero