import React, { useState, useEffect, useCallback } from 'react';
import { Link, useLocation } from 'react-router-dom';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Button from 'react-bootstrap/Button';
import CountUp from 'react-countup';

import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";

import * as EgovNet from 'api/egovFetch';
import URL from 'constants/url';

function EgovMain(props) {
    console.group("EgovMain");
    console.log("[Start] EgovMain ------------------------------");
    console.log("EgovMain [props] : ", props);

    const location = useLocation();
    console.log("EgovMain [location] : ", location);

    const settings = {
        dots: false,
        infinite: true,
        speed: 500,
        slidesToShow: 6,
        slidesToScroll: 1,
        arrows: false,
        autoplay: true,
        autoplaySpeed: 3000,
        pauseOnHover: true
    };

    const banners = [
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/copy2.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/copy2.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/copy2.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/copy2.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        { src: '/assets/images/f-logo.png', url: 'https://talbakkum.com' },
        // 필요한 만큼 배너 이미지를 추가합니다.
    ];

	// eslint-disable-next-line no-unused-vars
    const [noticeBoard, setNoticeBoard] = useState();
	// eslint-disable-next-line no-unused-vars
    const [gallaryBoard, setGallaryBoard] = useState();
    const [noticeListTag, setNoticeListTag] = useState();
    const [gallaryListTag, setGallaryListTag] = useState();

    const retrieveList = useCallback(() => {
        console.groupCollapsed("EgovMain.retrieveList()");

        const retrieveListURL = '/';
        const requestOptions = {
            method: "POST",
            headers: {
                'Content-type': 'application/json'
            },
            body: JSON.stringify()
        }

        EgovNet.requestFetch(retrieveListURL,
            requestOptions,
            (resp) => {

                setNoticeBoard(resp.result.notiList);
                setGallaryBoard(resp.result.galList);

                let mutNotiListTag = [];
                mutNotiListTag.push(<li key="0">검색된 결과가 없습니다.</li>); // 게시판 목록 초기값

                // 리스트 항목 구성
                resp.result.notiList.forEach(function (item, index) {
                    if (index === 0) mutNotiListTag = []; // 목록 초기화
                    mutNotiListTag.push(
                        <li key={item.nttId}>
                            <Link
                                to={{pathname: URL.INFORM_NOTICE_DETAIL}}
                                state={{
                                    nttId: item.nttId,
                                    bbsId: item.bbsId
                                }}
                            >
                                {item.nttSj}
                                <span>{item.frstRegisterPnttm}</span>
                            </Link>
                        </li>
                    );
                });
                setNoticeListTag(mutNotiListTag);

                let mutGallaryListTag = [];
                mutGallaryListTag.push(<li key="0">검색된 결과가 없습니다.</li>); // 게시판 목록 초기값

                // 리스트 항목 구성
                resp.result.galList.forEach(function (item, index) {
                    if (index === 0) mutGallaryListTag = []; // 목록 초기화
                    mutGallaryListTag.push(
                        <li key={index}>
                            <Link
                                to={{pathname: URL.INFORM_GALLERY_DETAIL}}
                                state={{
                                    nttId: item.nttId,
                                    bbsId: item.bbsId
                                }}
                            >
                                {item.nttSj}
                                <span>{item.frstRegisterPnttm}</span>
                            </Link>
                        </li>
                    );
                });
                setGallaryListTag(mutGallaryListTag);
            },
            function (resp) {
                console.log("err response : ", resp);
            }
        );
        console.groupEnd("EgovMain.retrieveList()");
    },[]);

    useEffect(() => {
        retrieveList();
    }, [retrieveList]);

    console.log("------------------------------EgovMain [End]");
    console.groupEnd("EgovMain");

    return (
        <div className="P_MAIN">{/* container */}
            <div className="c_wrap">
                <div className="topbox d-flex justify-content-center align-items-center">
                    <div className="topbox_1"></div>
                    <div className="topbox_2"></div>
                    <div className="topbox_3"></div>
                </div>
                <div className="menubox d-flex justify-content-center align-items-center">
                    <div className="menubox_n text-center"><Link to={URL.STANDARD_CODE_OLD}><div className="menu_img"><img src="/assets/images/ico-landing5.png" /></div><div className="menu_text">훈령/예규/지침</div></Link></div>
                    <div className="menubox_n text-center"><Link to={URL.STANDARD_CODE_ENG}><div className="menu_img"><img src="/assets/images/ico-landing6.png" /></div><div className="menu_text">영문건설기준</div></Link></div>
                    <div className="menubox_n text-center"><Link to={URL.STANDARD_CODE_TERM}><div className="menu_img"><img src="/assets/images/ico-landing8.png" /></div><div className="menu_text">건설기준용어</div></Link></div>
                    <div className="menubox_n text-center"><Link to={URL.SUPPORT_LIST}><div className="menu_img"><img src="/assets/images/ico-landing7.png" /></div><div className="menu_text">주요행사</div></Link></div>
                    <div className="menubox_n text-center"><Link to={URL.SUPPORT_LIST}><div className="menu_img"><img src="/assets/images/ico-landing9.png" /></div><div className="menu_text">수요조사</div></Link></div>
                    <div className="menubox_n text-center"><Link to={URL.SUPPORT_API}><div className="menu_img"><img src="/assets/images/ico-landing10.png" /></div><div className="menu_text">API 서비스</div></Link></div>
                    <div className="menubox_n text-center"><Link to={URL.SUPPORT_SITE}><div className="menu_img"><img src="/assets/images/ico-landing11.png" /></div><div className="menu_text">관련사이트</div></Link></div>
                </div>
                <div className="qnabox">

                </div>
                <div className="numbox d-flex justify-content-center align-items-center">
                    <div className="numbox_n"><div className="num_text">다운로드 수</div><div className="num_count"><CountUp start={0} end={334345} duration={2.5} separator="," /><span className="unit">건</span></div></div>
                    <div className="numbox_n"><div className="num_text">회원가입자 수</div><div className="num_count"><CountUp start={0} end={12345} duration={2.5} separator="," /><span className="unit">명</span></div></div>
                    <div className="numbox_n"><div className="num_text">일 편균 방문자</div><div className="num_count"><CountUp start={0} end={56427} duration={2.5} separator="," /><span className="unit">명</span></div></div>
                    <div className="numbox_n"><div className="num_text">개정고시</div><div className="num_count"><CountUp start={0} end={99875} duration={2.5} separator="," /><span className="unit">건</span></div></div>
                </div>
                <div className="bbsbox d-flex justify-content-center align-items-center">
                    <div className="bbsbox_1">1</div>
                    <div className="bbsbox_2">2</div>
                </div>
                <div className="bannerbox">
                    <Slider {...settings}>
                        {banners.map((banner, index) => (
                            <div key={index} className="banner_slide d-flex justify-content-center align-items-center">
                                <a href={banner.url} target="_blank" rel="noopener noreferrer">
                                    <img src={banner.src} alt={`Banner ${index + 1}`} />
                                </a>
                            </div>
                        ))}
                    </Slider>
                </div>
            </div>
        </div>

    );
}

export default EgovMain;
