"use-strict";

/*소통 정보*/
var sideInfoList = true;
function atrdTrfInfo(atrdId) {
    if (atrdId == '') {
    	return;
    }

    _AtrdId         = atrdId;
    const infoArr   = _AtrdId.split(',');
    const frontId   = infoArr[0];
    const endId     = infoArr[1];
    const className = 'atrd'+ infoArr[2];
    const traffArr  = _TrafficInfoArr[_Level];
    _AtrdBounds     = new daum.maps.LatLngBounds();

    if (traffArr && traffArr.length > 0) {
        if (_AtrdSideMarkerArr.length > 0) {
            _AtrdSideMarkerArr[0].setMap(null);
            _AtrdSideMarkerArr[1].setMap(null);
            _AtrdSideMarkerArr = [];
        }
        _AtrdFrontPoly = null;
        _AtrdBackPoly  = null;
        traffArr.forEach((obj)=>{
            if (obj.atrd_id === frontId) {
                if (!_AtrdFrontPoly) _AtrdFrontPoly = obj.polyline;
                _AtrdBounds.extend(new daum.maps.LatLng(obj.y_crdn_min, obj.x_crdn_min));
                _AtrdBounds.extend(new daum.maps.LatLng(obj.y_crdn_max, obj.x_crdn_max));
            }
            if (endId === obj.atrd_id) {
                if (!_AtrdBackPoly) _AtrdBackPoly = obj.polyline;
            }
        })

        if (_AtrdSideMarkerArr && _AtrdSideMarkerArr.length > 0) {
            _AtrdSideMarkerArr.forEach((obj)=>{
                obj.setMap(null);
            })
        }

        if ($('.traffic-realtime-wrap').css('display') == 'none') {
            _Map.setBounds(_AtrdBounds);
        }
        drawAtrdSideMarker('S', _AtrdFrontPoly.getPath()[0].getLat(), _AtrdFrontPoly.getPath()[0].getLng());
        drawAtrdSideMarker('E', _AtrdBackPoly.getPath()[0].getLat(), _AtrdBackPoly.getPath()[0].getLng());

        drawVertexArr();

    }

    $('#atrdList').val(atrdId);
    $('.road > li').css('background-color', '#ffffff');
    $('.' + className).css('background-color', '#eee');
}

function isNumber(value, lineNum, fixedNum) {
    if (value === null || value === undefined || isNaN(Number(value)) || value === 0) {
        return '-';
    }

    if (lineNum && !isNaN(Number(lineNum))) {
        value = (value/lineNum);
    }

    value = Number(value).toFixed(fixedNum);
    return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

function isNumberText(number, text){
	let format = '';
	if (isNaN(number)) {
		format = '-' + text;
	}
	else {
		format = number + text;
	}
	return format;
}

function drawAtrdSideMarker(src, lat, lng) {
    var imageSize;
    var imageSrc = '/images/traffic/map-marker' + src + '.png'; // 마커이미지의 주소입니다
    if (_Level < 7) {
        imageSize = new daum.maps.Size(48, 48);
        imageOption = { offset: new daum.maps.Point(24, 48) };
    } else {
        imageSize = new daum.maps.Size(24, 24);
        imageOption = { offset: new daum.maps.Point(12, 24) };
    }

    // 마커의 이미지정보를 가지고 있는 마커이미지를 생성합니다
    var markerImage = new daum.maps.MarkerImage(imageSrc, imageSize, imageOption),
        markerPosition = new daum.maps.LatLng(lat, lng); // 마커가 표시될 위치입니다

    // 마커를 생성합니다
    var atrdSideMarker = new daum.maps.Marker({map: _Map, position: markerPosition, image: markerImage, zIndex: 5});
    _AtrdSideMarkerArr.push(atrdSideMarker);
}

function typeOfMap() {
    $('.mapContent.traffic-realtime-wrap').addClass('hide');
    $('.mapContent.map').removeClass('hide');
    _Map.relayout();
    _Map.setBounds(_AtrdBounds);
}

function typeOfLetters() {
    $('.mapContent.map').addClass('hide');
    $('.mapContent.traffic-realtime-wrap').removeClass('hide');
    $('#mapOfLetters').empty().html(_RoadListStr);
}

function sideListShow(content) {
    if (sideInfoList == true) {
        $('.hideShowButton').attr('title', content+'목록보기');
        $('.hideShowButton').css(
            'background',
            'url("/images/btn_showhide.png") 0 -30px no-repeat'
        );
        $('.sideInfoList').hide();
        sideInfoList = false;
    } else {
        $('.hideShowButton').attr('title', content+'목록숨김');
        $('.hideShowButton').css(
            'background',
            'url("/images/btn_showhide.png") 0 0 no-repeat'
        );
        $('.sideInfoList').show();
        sideInfoList = true;
    }
}

/*CCTV 정보*/

function showCctvInfo(id,nm) {
	$('#selectCctv').text(nm+' 지도 CCTV 정보');
    _CctvCtlrArr.some(function (el) {
        if (el.cctv_mngm_nmbr == id) {
            _Map.panTo(new daum.maps.LatLng(el.y_crdn, el.x_crdn));
            //setTimeout(function () {
                el.cctvClickEvt(el);

                
           // }, 100 * 5);
            return true;
        }
    });
}
/*VMS 정보*/

function showVmsInfo(id,nm) {
	$('#selectVms').text(nm+' 지도 VMS 정보');
    _VmsCtlrArr.some(function (el) {
        if (el.vms_ctlr_nmbr == id) {
            _Map.panTo(new daum.maps.LatLng(el.y_crdn, el.x_crdn));
            
            //setTimeout(function () {
                el.vmsClickEvt(el);
            //}, 100 * 5);
                $('#vmsClose').focus();
            return false;
        }
    });
}

/*돌발 정보*/

function showIncdInfo(id,nm) {

	$('#selectIncd').text(nm+' 지도 돌발 정보');
    var lettersStr = '';
    _IncdOcrrArr.some(function (el) {
        if (el.incd_ocrr_id == id) {
            _Map.panTo(new daum.maps.LatLng(el.y_crdn, el.x_crdn));
            el.incdClickEvt();
            $('#incdClose').focus();
            if (_RoadListStr != '' && _RoadListStr.length > 0) {
                _RoadListStr = '';
                $('#mapOfLetters').empty();
            }

            lettersStr += '<tr><td style="width:30% !important"><a href="javascript:void(0)" title="제목:' +
                    el.incd_titl + '">[' + el.incd_titl + '] <strong>' + el.road_name + '</strong><' +
                    '/a></td><td style="width:30% !important"><a href="javascript:void(0)" title="위' +
                    '치:' + el.road_name + '">위치 : ' + el.road_name + '</a></td><td><a href="javascr' +
                    'ipt:void(0)" title="설명:' + el.incd_expl + '">설명 : ' + el.incd_expl +
                    '</a></td>'
            '<td><a href="javascript:void(0)" title="기간:' + el.incd_strt_dt + '부터' + el.incd_end_prar_dt +
                    '까지">기간 : ' + el.incd_strt_dt + ' 부터 <p>' + el.incd_end_prar_dt + ' 까지</p></a><' +
                    '/td></tr>';

            _RoadListStr = lettersStr;
            $('#mapOfLetters')
                .empty()
                .html(_RoadListStr);

            return true;
        }
    });

    //돌발목록에서 돌발선택시 문자탭으로 이동..
   // $('#mapOfLetters tr:nth-of-type(1) td:nth-of-type(1) a').focus();
}

/*주차 정보*/
//
// function showParkingInfo(id,nm,comm) {
// 	$('#selectParking').text(nm+' 지도 주차 정보');
//     if (_Level != 3)
//         _Map.setLevel(3);
//
//     _ParkingInfoArr.some(function (el) {
//         if (el.park_id == id) {
//             _Map.setCenter(new daum.maps.LatLng(el.x_crdn, el.y_crdn));
//             el.parkingClickEvt(comm);
//
//             parrkingInfoStr(
//                 el.park_id,
//                 el.park_nm,
//                 el.park_type_cd,
//                 el.park_fee,
//                 el.park_num,
//                 el.addr,
//                 el.x_crdn,
//                 el.y_crdn,
//                 el.rmrk
//             );
//             return;
//         } else if (el.park_nm == id) {
//             _Map.setCenter(new daum.maps.LatLng(el.x_crdn, el.y_crdn));
//             el.parkingClickEvt(comm);
//
//             parrkingInfoStr(
//                 el.park_id,
//                 el.park_nm,
//                 el.park_type_cd,
//                 el.park_fee,
//                 el.park_num,
//                 el.addr,
//                 el.x_crdn,
//                 el.y_crdn,
//                 el.rmrk
//             );
//             return;
//         }
//     });
//     //$('.parkingInfo ul li:nth-of-type(1) span a').focus();
// }
//
// var beforeParkingLot = null;
// function parrkingInfoStr(
//     park_id,
//     park_nm,
//     park_type_cd,
//     park_fee,
//     park_num,
//     addr,
//     x_crdn,
//     y_crdn,
//     rmrk
// ) {
//
//     if (beforeParkingLot != null) {
//         beforeParkingLot.attr('style', 'background-color:#fff');
//     }
//     beforeParkingLot = $(park_id).css('background-color', '#dcdcdc');
//     var typeCd = park_type_cd == 1? '노상': park_type_cd == 2 ? '노외': '부설';
//     var fee = park_fee == null? '정보없음': park_fee == 1? '유료': '무료';
//
//     var content = '';
//
//     /*	content += '<ul><li><label>주차면수</label><span><a href="javascript:void(0)" title="주차면수: 대" tabindex="24">'+park_num+'</a></span></li>';
// 	content += '<li><label>장애인 주차</label><span><a href="javascript:void(0)" title="장애인주차:대" tabindex="24">-</a></span></li>';
// 	content += '<li><label>구분</label><span><a href="javascript:void(0)" title="구분:공영 / 노외" tabindex="24">'+typeCd+'</a></span></li>';
// 	content +='<li><label>기본요금</label><span><a href="javascript:void(0)" title="기본요금: 분 무료" tabindex="24">'+fee+'</a></span></li>';
// 	content += '<li><label>추가요금</label><span><a href="javascript:void(0)" title="소형요금:원 / 30분" tabindex="24">-</a></span></li>';
// 	content +='<li><span style="margin-left:60px"><a href="javascript:void(0)" title="소형최대요금:원 / 일" tabindex="24">-</a></span></li>';
// 	content += '<li><span style="margin-left:60px"><a href="javascript:void(0)" title="대형요금:원 / 30분" tabindex="24">-</a></span></li>';
// 	content += '<li><span style="margin-left:60px"><a href="javascript:void(0)" title="대형최대요금:원 / 일" tabindex="24">-</a></span></li>';
// 	content += '<li><label>주소</label><span><a href="javascript:void(0)" title=주소"" tabindex="24">'+addr+'</a></span></li>';
// 	content += '<li><label>연락처</label><span><a href="javascript:void(0)" title="연락처" tabindex="24">-</a></span></li></ul>';
// 	*/
//     content += '<ul><li><label>주차면수</label><span><a href="javascript:void(0)" title="주차면수: 대" ' +
//             'tabindex="24">' + park_num + '</a></span></li>';
//     content += '<li><label>구분</label><span><a href="javascript:void(0)" title="구분:공영 / 노외" tab' +
//             'index="24">' + typeCd + '</a></span></li>';
//     content += '<li><label>기본요금</label><span><a href="javascript:void(0)" title="기본요금: 분 무료" t' +
//             'abindex="24">' + fee + '</a></span></li>';
//     content += '<li><label>주소</label><span><a href="javascript:void(0)" title=주소"" tabindex="2' +
//             '4">' + addr + '</a></span></li>';
//
//     $('.parkingInfo')
//         .empty()
//         .html(content);
// }

$('.dis li').on('click', function (){
    for (let ii = 0; ii < $('.dis li').length; ii ++) {
        $('.dis li').eq(ii).css('background-color', '#fff');
        if ($('.dis li')[ii] === $(this)[0]) {
            $(this).css('background-color', '#eee');
        }
    }

})