import React from 'react';
import { useLocation } from 'react-router-dom';
import { NavLink } from 'react-router-dom';
import URL from 'constants/url';
import {Accordion} from "react-bootstrap";

function EgovLeftNavAdmin(props) {
    const location = useLocation();

    const getMiddleFolder = (url) => {                      // 중간 폴더를 가져오는 로직 추가
        const parts = url.split('/').filter(Boolean);           // '/'로 분할하고 빈 문자열을 필터링
        if (parts.length >= 2) {
            return parts[1];                                    // 중간 폴더 반환
        }
        return null;
    };
    const activeFolder = getMiddleFolder(location.pathname);

    let activeKey;
    if (activeFolder === "config") {
        activeKey = "0";
    } else if (activeFolder === "users") {
        activeKey = "1";
    } else if (activeFolder === "boards") {
        activeKey = "2";
    } else if (activeFolder === "standards") {
        activeKey = "3";
    } else if (activeFolder === "contents") {
        activeKey = "4";
    } else if (activeFolder === "committee") {
        activeKey = "5";
    } else if (activeFolder === "logs") {
        activeKey = "6";
    } else {
        activeKey = "7";
    }

    return (
        <div className="nav">
            <div className="inner">
                <h2 className={"nav_title"}>사이트관리</h2>
                <Accordion defaultActiveKey={activeKey}>
                    <Accordion.Item eventKey={"7"}>
                        <Accordion.Header>사이트 관리</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN_SCHEDULE} className={({ isActive }) => (isActive ? "cur" : "")}>Dashboard</NavLink></li>
                                {/*<li><NavLink to={URL.ADMIN_BOARD} className={({ isActive }) => (isActive ? "cur" : "")}>게시판생성관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_USAGE} className={({ isActive }) => (isActive ? "cur" : "")}>게시판사용관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_NOTICE} className={({ isActive }) => (isActive ? "cur" : "")}>공지사항관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_GALLERY} className={({ isActive }) => (isActive ? "cur" : "")}>사이트갤러리관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_MANAGER} className={({ isActive }) => (isActive ? "cur" : "")}>사이트관리자 암호변경</NavLink></li>*/}
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                    <Accordion.Item eventKey={"0"}>
                        <Accordion.Header>환경설정</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN_BASE_CODE} className={({ isActive }) => (isActive ? "cur" : "")}>기본코드 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_STANDARD_CODE} className={({ isActive }) => (isActive ? "cur" : "")}>건설기준코드 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_COMMITTEE_CODE} className={({ isActive }) => (isActive ? "cur" : "")}>위원회코드 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_MENU} className={({ isActive }) => (isActive ? "cur" : "")}>메뉴 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_MENU_AUTH} className={({ isActive }) => (isActive ? "cur" : "")}>메뉴권한 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN_ABOUT_SITE} className={({ isActive }) => (isActive ? "cur" : "")}>관련사이트 관리</NavLink></li>
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                    
                    <Accordion.Item eventKey={"1"}>
                        <Accordion.Header>사용자 관리</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN__USERS__LIST} className={({ isActive }) => (isActive ? "cur" : "")}>사용자 목록</NavLink></li>
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                    
                    <Accordion.Item eventKey={"2"}>
                        <Accordion.Header>게시판현황</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN__BOARDS__LIST} className={({ isActive }) => (isActive ? "cur" : "")}>게시판 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__BOARDS__POSTS} className={({ isActive }) => (isActive ? "cur" : "")}>게시물 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__BOARDS__KEYWORDS} className={({ isActive }) => (isActive ? "cur" : "")}>키워드 관리</NavLink></li>
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                    
                    <Accordion.Item eventKey={"3"}>
                        <Accordion.Header>건설기준관리</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN__STANDARDS__REFERENCE_CODES} className={({ isActive }) => (isActive ? "cur" : "")}>참조코드 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__STANDARDS__API_KYES} className={({ isActive }) => (isActive ? "cur" : "")}>API KEY 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__STANDARDS__SIMILARITY_CHECK} className={({ isActive }) => (isActive ? "cur" : "")}>유사성 검사</NavLink></li>
                                <li><NavLink to={URL.ADMIN__STANDARDS__INFO_DISCLOSURE} className={({ isActive }) => (isActive ? "cur" : "")}>건설기준 내용 관리</NavLink></li>
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>                    

                    <Accordion.Item eventKey={"4"}>
                        <Accordion.Header>컨텐츠관리</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN__CONTENTS__SURVEY} className={({ isActive }) => (isActive ? "cur" : "")}>설문 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__CONTENTS__POP_UP} className={({ isActive }) => (isActive ? "cur" : "")}>팝업 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__CONTENTS__STANDARDS_RESEARCH} className={({ isActive }) => (isActive ? "cur" : "")}>건설기준연구 관리</NavLink></li>
                                {/*<li><NavLink to={URL.ADMIN__CONTENTS__TEXT_MESSAGES} className={({ isActive }) => (isActive ? "cur" : "")}>문자 발송</NavLink></li>*/}
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                    
                    <Accordion.Item eventKey={"5"}>
                        <Accordion.Header>위원회관리</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN__COMMITTEE__PROGRESS_STATUS} className={({ isActive }) => (isActive ? "cur" : "")}>진행현황 관리</NavLink></li>
                                <li><NavLink to={URL.ADMIN__COMMITTEE__SCHEDULES} className={({ isActive }) => (isActive ? "cur" : "")}>위원회 일정 관리</NavLink></li>
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                    
                    <Accordion.Item eventKey={"6"}>
                        <Accordion.Header>로그현황</Accordion.Header>
                        <Accordion.Body>
                            <ul className="menu4">
                                <li><NavLink to={URL.ADMIN__LOGS__MENU_ACCESS_INFO} className={({ isActive }) => (isActive ? "cur" : "")}>메뉴별 접속 현황</NavLink></li>
                                <li><NavLink to={URL.ADMIN__LOGS__USER_CONNECTIONS} className={({ isActive }) => (isActive ? "cur" : "")}>사용자 접속 현황</NavLink></li>
                                <li><NavLink to={URL.ADMIN__LOGS__PRIVACY_LOGS} className={({ isActive }) => (isActive ? "cur" : "")}>개인정보 로그</NavLink></li>
                                <li><NavLink to={URL.ADMIN__LOGS__FILE_DOWNLOAD_STATUS} className={({ isActive }) => (isActive ? "cur" : "")}>파일 다운 현황</NavLink></li>
                            </ul>
                        </Accordion.Body>
                    </Accordion.Item>
                </Accordion>

            </div>
        </div>
    );
}

export default React.memo(EgovLeftNavAdmin);