import React, { useState, useEffect } from 'react';
import { Link, useLocation, useNavigate } from 'react-router-dom';

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

import { default as EgovLeftNav } from 'components/leftmenu/EgovLeftNavAdmin';

function SchedulesDetail(props) {
    console.group("EgovAdmindetailItem");
    console.log("EgovAdmindetailItem [props] : ", props);

    const navigate = useNavigate();
    const location = useLocation();

    const [detailItem, setDetailItem] = useState({});
    
    const retrieveDetail = () => {
        
        const retrieveDetailURL = `/admin/committee/progress-status/${location.state?.drftSeq}`;
        const requestOptions = {
            method: "GET",
            headers: {
                'Content-type': 'application/json',
            }
        }
        EgovNet.requestFetch(retrieveDetailURL,
            requestOptions,
            function (resp) {
                setDetailItem(resp.result.item);
            }
        );
    }

    const onClickDeleteSchedule = (drftSeq) => {
        const deleteBoardURL = `/admin/committee/progress-status/${drftSeq}`;

        const requestOptions = {
            method: "DELETE",
            headers: {
                'Content-type': 'application/json',
            }
        }

        EgovNet.requestFetch(deleteBoardURL,
            requestOptions,
            (resp) => {
                console.log("====>>> Schdule delete= ", resp);
                if (Number(resp.resultCode) === Number(CODE.RCV_SUCCESS)) {
                    alert("게시글이 삭제되었습니다.")
                    navigate(URL.ADMIN__COMMITTEE__SCHEDULES ,{ replace: true });
                } else {
                    // alert("ERR : " + resp.message);
                    navigate({pathname: URL.ERROR}, {state: {msg : resp.resultMessage}});
                }

            }
        );
    }

    useEffect(function () {
        retrieveDetail();
    // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);

    console.groupEnd("EgovAdmindetailItem");
    return (
        <div className="container">
            <div className="c_wrap">
                {/* <!-- Location --> */}
                <div className="location">
                    <ul>
                        <li><Link to={URL.MAIN} className="home">Home</Link></li>
                        <li><Link to={URL.ADMIN}>사이트관리</Link></li>
                        <li>위원회관리</li>
                        <li>진행현황 관리</li>
                    </ul>
                </div>
                {/* <!--// Location --> */}

                <div className="layout">
                    {/* <!-- Navigation --> */}
                    <EgovLeftNav></EgovLeftNav>
                    {/* <!--// Navigation --> */}

                    <div className="contents SITE_GALLARY_VIEW" id="contents">
                        {/* <!-- 본문 --> */}

                        <div className="top_tit">
                            <h1 className="tit_1">진행현황 관리</h1>
                        </div>

                        {/* <!-- 게시판 상세보기 --> */}
                        <div className="board_view2">
                            <dl>
                                <dt>안건</dt>
                                <dd>{detailItem.title}</dd>
                            </dl>
                            <dl>
                                <dt>기준코드</dt>
                                <dd>{detailItem.standardCode}</dd>
                            </dl>
                            <dl>
                                <dt>구분</dt>
                                <dd>{detailItem.drftTypeNm}</dd>
                            </dl>
                            <dl>
                                <dt>회의일자</dt>
                                <dd>{detailItem.regDate}</dd>
                            </dl>                            
                            <dl>
                                <dt>위원회</dt>
                                <dd> {detailItem.orgNm}</dd>
                            </dl>
                            <dl>
                                <dt>회의담당자</dt>
                                <dd>{detailItem.drftConfeCharger}</dd>
                            </dl>
                            <dl>
                                <dt>회의실 비밀번호</dt>
                                <dd>{detailItem.drftConfePw}</dd>
                            </dl>
                            <dl>
                                <dt>사전검토자료</dt>
                                <dd>{detailItem.seq}</dd>
                            </dl>
                            <dl>
                                <dt>사전검토양식</dt>
                                <dd>{detailItem.seq}</dd>
                            </dl>
                            <dl>
                                <dt>관계기관의견</dt>
                                <dd>{detailItem.seq}</dd>
                            </dl>
                            <dl>
                                <dt>조치계획서</dt>
                                <dd>{detailItem.seq}</dd>
                            </dl>
                            <dl>
                                <dt>조치결과서</dt>
                                <dd>{detailItem.seq}</dd>
                            </dl>
                            <dl>
                                <dt>회의 안건</dt>
                                <dd>{detailItem.drftSummery}</dd>
                            </dl>
                            <dl>
                                <dt>회의 내용</dt>
                                <dd>{detailItem.seq}</dd>
                            </dl>

                            {/* <!-- 버튼영역 --> */}
                            <div className="board_btn_area">
                                <div className="right_col btn1">
                                    <Link to={URL.ADMIN__COMMITTEE__PROGRESS_STATUS} className="btn btn_blue_h46 w_100">목록</Link>
                                </div>
                            </div>
                            {/* <!--// 버튼영역 --> */}

                            
                        </div>
                        {/* <!-- 게시판 상세보기 --> */}

                        {/* <!--// 본문 --> */}
                    </div>
                </div>
            </div>
        </div>
    );
}

export default SchedulesDetail;