/* 페이징 관련 변수 */
let userPushHistoryTotalCount   = 0;
let userPushHistoryTotalPages   = 0;

/*aggird*/
let userPushHistoryAgGridData = [];

let userPushHistorySelectId = "";

/****************************************************************************
* 검색 날짜 설정
//(A:오늘, B:3일, C:7일, D:최근30일, E:최근90일, F:이번달, G:올해, H:지난주, I:지난달)
****************************************************************************/
function fn_userPushHistorySetDate(param){
	if("A"==param){
		// 오늘
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchStartDate = year+'-'+month+'-'+day;
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
	}
	else if("B"==param){
		// 3일
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		toDate.setDate(toDate.getDate() - 3);
		year  = toDate.getFullYear();
		month = toDate.getMonth() + 1;
		day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchStartDate = year+'-'+month+'-'+day;
	}
	else if("C"==param){
		// 이번주
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		toDate.setDate(toDate.getDate() - 7);
		year  = toDate.getFullYear();
		month = toDate.getMonth() + 1;
		day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchStartDate = year+'-'+month+'-'+day;
	}
	else if("D"==param){
		// 최근30일
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		//최근30일
		toDate.setDate(toDate.getDate() - 30);
		startYear  = toDate.getFullYear();
		startMonth = toDate.getMonth() + 1;
		startDay   = toDate.getDate();
		
		if(startMonth < 10) startMonth = "0" + startMonth;
		if(startDay < 10) startDay = "0" + startDay;
		
		userPushHistorySearchStartDate = startYear+'-'+startMonth+'-'+startDay;
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
	}
	else if("E"==param){
		// 최근90일
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		toDate.setDate(toDate.getDate() - 90);
		year  = toDate.getFullYear();
		month = toDate.getMonth() + 1;
		day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchStartDate = year+'-'+month+'-'+day;
	}
	else if("F"==param){
		//F:이번달
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		userPushHistorySearchStartDate = year+'-'+month+'-01';
	}
	else if("G"==param){
		// G:올해
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		userPushHistorySearchStartDate = year+'-01-01';
	}
	else if("H"==param){
		// H:지난주, I:지난달
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		userPushHistorySearchStartDate = year+'-01-01';
	}
	else if("I"==param){
		// I:지난달
		// 검색 종료일자
		let toDate = new Date();
		let year  = toDate.getFullYear();
		let month = toDate.getMonth() + 1;
		let day   = toDate.getDate();
		
		if(month < 10) month = "0" + month;
		if(day < 10) day = "0" + day;
		
		userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
		
		// 검색 시작일자
		userPushHistorySearchStartDate = year+'-01-01';
	}
	
	$("#userPushHistorySearchStartDate").val(userPushHistorySearchStartDate).trigger("change");
	$("#userPushHistorySearchEndDate").val(userPushHistorySearchEndDate).trigger("change");
}

/****************************************************************************
* 콤보 선택 이벤트
****************************************************************************/
function fn_setComboEvent(param, clickCallEvent, firstCheckYn){
	let target = param.next(".select_option_list");
		
	target.find("li.option_list_item").click(function () {
		// 1. 선택값 셋팅
		let selectId    = $(this).find('input[name="comboId"]').val();
		let selectName  = $(this).find('span').text(); 
		
		$(this).parent().siblings("button").text(selectName);
		$(this).parent().siblings("input").val(selectId);
		
		if( clickCallEvent )  {
			clickCallEvent(selectId);
		}
	});
	
	// 초기화
	if('Y' == firstCheckYn){
		target.find("li:eq(0)").click();
	}
}

/****************************************************************************
 * 고객 - 알림 내역 리스트 조회
 ****************************************************************************/
function fn_selectListUserPushHistoryJson(){
    let formData = new FormData();
    formData.append("menuClass", menuClass);
    formData.append("searchKeywordParam", userPushHistorySearchKeywordParam);
    formData.append("sort", userPushHistorySort);
    formData.append("dir", userPushHistoryDir);
    formData.append("start", userPushHistoryStart);
    formData.append("limit", userPushHistoryLimit);
    formData.append("searchStartDate", userPushHistorySearchStartDate);
    formData.append("searchEndDate", userPushHistorySearchEndDate);
    formData.append("searchDateType", userPushHistorySearchDateType);
    formData.append("searchType", userPushHistorySearchType);
    formData.append("muUserId", muUserId);

    $.ajax({
        url: encodeURI('/webuserpushhistory/selectListUserPushHistory.do'),
        data: formData,
        dataType: "json",
        processData: false,
        contentType: false,
        type: 'POST',
        async: true,
        success: function(data){
            if('0'==data.msgCode){
                // 페이징 처리
                userPushHistoryTotalCount  = data.totalCount;
                //$("#txt_userPushHistoryTotalCount").text(userPushHistoryTotalCount);
                
                userPushHistoryAgGridData = data.rows;
                userPushHistoryGridOptions.api.setRowData(userPushHistoryAgGridData);
                if(0<data.rows.length){
                    //페이징 처리
                    window.pagObj = $('#userPushHistoryPagination').twbsPagination({
                        startPage    : ((userPushHistoryStart/userPushHistoryLimit)+1),
                        totalPages   : (userPushHistoryTotalPages==0)?1:userPushHistoryTotalPages,
                        visiblePages : 10,
                        initiateStartPageClick: false,
                        prev         : '<img src="/image/web/page_navigation_arrow.svg" alt="prev"/>',
                        next         : '<img src="/image/web/page_navigation_arrow.svg" alt="next"/>',
                        first        : '',
                        last         : '',
                        onPageClick: function (event, page) {
                            fn_userPushHistoryPagination(page);
                        }
                    }).on('page', function (event, page) {
                        //console.info(page + ' (from event listening)');
                    });
                }
                else{

                }
            }
            else{
                modalEvent.danger("조회 오류", data.msgDesc);
            }
        },
        error : function(xhr, status, error) {
            modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
        },
        beforeSend:function(){
            // 로딩열기
            userPushHistoryGridOptions.api.showLoadingOverlay();
        },
        complete:function(){

        }
    });
}

/****************************************************************************
 * 검색하기
 ****************************************************************************/
function fn_userPushHistorySearch(param){
    if("A"!=param && "Y"!=selectUseYn){
        modalEvent.warning("", "조회 권한이 없습니다.");
        return false;
    }

    fn_userPushHistoryPaginReset();

    userPushHistorySearchKeywordParam = $("#userPushHistorySearchKeyword").val()??'';

    userPushHistorySearchDateType  = $("#userPushHistorySearchDateType").val();
    userPushHistorySearchStartDate = $("#userPushHistorySearchStartDate").val();
    userPushHistorySearchEndDate   = $("#userPushHistorySearchEndDate").val();

    userPushHistorySearchType  = $("#userPushHistorySearchType").val();

    fn_selectListUserPushHistoryJson();
}
/****************************************************************************
 * 검색 엔터 이벤트
 ****************************************************************************/
function fn_userPushHistoryEnter(e){
    if(e.which){
        // 파이어폭스
        if(13 == e.which) {
            //로그인 액션 스크립트
            fn_userPushHistorySearch();
        }
    }
    else{
        // 윈도우, 사파리, 크롬
        if(13 == event.keyCode) {
            //로그인 액션 스크립트
            fn_userPushHistorySearch();
        }
    }
}
/****************************************************************************
 * 엑셀 다운 다운로드
 ****************************************************************************/
function fn_downloadExcel(){
    if("Y"==downloadUseYn){
        // 수정가능
        let pagingParam = "?menuClass="+menuClass;
        pagingParam    += "&searchKeywordParam="+userPushHistorySearchKeywordParam;
        pagingParam    += "&sort="+userPushHistorySort;
        pagingParam    += "&dir="+userPushHistoryDir;
        pagingParam    += "&start="+userPushHistoryStart;
        pagingParam    += "&limit="+userPushHistoryLimit;
        pagingParam    += "&searchStartDate="+userPushHistorySearchStartDate;
        pagingParam    += "&searchEndDate="+userPushHistorySearchEndDate;
        pagingParam    += "&searchDateType="+userPushHistorySearchDateType;
        pagingParam    += "&searchType="+userPushHistorySearchType;
        pagingParam    += "&muUserId="+muUserId;
        
        var url = encodeURI("/webuserpushhistory/downloadUserPushHistoryExcel.do"+pagingParam);
        $("#userPushHistorySelectListForm").prop("action",url);
        $("#userPushHistorySelectListForm").submit();
    }
    else{
        modalEvent.warning("", "내려받기 권한이 없습니다.");
        return false;
    }
}
/****************************************************************************
 * 페이징 처리
 ****************************************************************************/
function fn_userPushHistoryPagination(param){
    userPushHistoryStart = (parseInt(param)-1)*userPushHistoryLimit;

    fn_selectListUserPushHistoryJson();
}
/****************************************************************************
 * 페이징 리셋
 ****************************************************************************/
function fn_userPushHistoryPaginReset(){
    userPushHistorySearchKeywordParam = '';

    userPushHistoryStart        = 0;
    userPushHistoryLimit        = 15;
    userPushHistoryTotalCount   = 0;
    userPushHistoryTotalPages   = 0;

    //페이징 초기화
    if($("#userPushHistoryPagination").data("twbs-pagination")){
        $("#userPushHistoryPagination").twbsPagination("destroy");
    }
}

/****************************************************************************
 * 진료구분 검색필터 세팅
 ****************************************************************************/
function setTreatmentOption(data){
    const ulElement = document.getElementById('userPushHistoryTreatmentId').nextElementSibling;

    data.forEach(treatment => {
        const liElement = document.createElement('li');
        liElement.className = 'option_list_item';
        liElement.textContent = treatment.treatmentName;
        liElement.id = treatment.muTreatmentId;

        ulElement.appendChild(liElement);
    });
}

/****************************************************************************
 * 검색 날짜 설정
 //(A:오늘, B:3일, C:7일, D:최근30일, E:최근90일, F:이번달, G:올해, H:지난주, I:지난달)
 ****************************************************************************/
function fn_userPushHistorySetDate(param){
    if("A"==param){
        // 오늘
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchStartDate = year+'-'+month+'-'+day;
        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
    }
    else if("B"==param){
        // 3일
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        toDate.setDate(toDate.getDate() - 3);
        year  = toDate.getFullYear();
        month = toDate.getMonth() + 1;
        day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchStartDate = year+'-'+month+'-'+day;
    }
    else if("C"==param){
        // 이번주
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        toDate.setDate(toDate.getDate() - 7);
        year  = toDate.getFullYear();
        month = toDate.getMonth() + 1;
        day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchStartDate = year+'-'+month+'-'+day;
    }
    else if("D"==param){
        // 최근30일
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        //최근30일
        toDate.setDate(toDate.getDate() - 30);
        startYear  = toDate.getFullYear();
        startMonth = toDate.getMonth() + 1;
        startDay   = toDate.getDate();

        if(startMonth < 10) startMonth = "0" + startMonth;
        if(startDay < 10) startDay = "0" + startDay;

        userPushHistorySearchStartDate = startYear+'-'+startMonth+'-'+startDay;
        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;

    }
    else if("E"==param){
        // 최근90일
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        toDate.setDate(toDate.getDate() - 90);
        year  = toDate.getFullYear();
        month = toDate.getMonth() + 1;
        day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchStartDate = year+'-'+month+'-'+day;
    }
    else if("F"==param){
        //F:이번달
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        userPushHistorySearchStartDate = year+'-'+month+'-01';
    }
    else if("G"==param){
        // G:올해
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        userPushHistorySearchEndDate   = year+'-'+month+'-'+day;
        // 검색 시작일자
        userPushHistorySearchStartDate = year+'-01-01';
    }
    else if("H"==param){
        // H:지난주, I:지난달
        // 검색 종료일자
        let toDate = new Date();
        let startDate = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate() - toDate.getDay() - 6); // 지난주 월요일
        let endDate = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate() - toDate.getDay()); // 지난주 일요일

        // 종료일자 설정
        let year = endDate.getFullYear();
        let month = endDate.getMonth() + 1; // JS의 getMonth()는 0부터 시작하므로 +1
        let day = endDate.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        userPushHistorySearchEndDate = year + '-' + month + '-' + day;

        // 시작일자 설정
        year = startDate.getFullYear();
        month = startDate.getMonth() + 1;
        day = startDate.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        userPushHistorySearchStartDate = year + '-' + month + '-' + day;
    }
    else if("I"==param){
        // I:지난달
        // I: 지난달
        let currentDate = new Date();
        let currentYear = currentDate.getFullYear();
        let currentMonth = currentDate.getMonth();

        // 지난달의 첫째 날
        let firstDayOfLastMonth = new Date(currentYear, currentMonth - 1, 1);
        let year = firstDayOfLastMonth.getFullYear();
        let month = firstDayOfLastMonth.getMonth() + 1; // JS는 월을 0부터 시작하므로 +1
        let day = firstDayOfLastMonth.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        userPushHistorySearchStartDate = year + '-' + month + '-' + day;

        // 지난달의 마지막 날
        let lastDayOfLastMonth = new Date(currentYear, currentMonth, 0);
        year = lastDayOfLastMonth.getFullYear();
        month = lastDayOfLastMonth.getMonth() + 1;
        day = lastDayOfLastMonth.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        userPushHistorySearchEndDate = year + '-' + month + '-' + day;
    }

    $("#userPushHistorySearchStartDate").val(userPushHistorySearchStartDate).trigger("change");
    $("#userPushHistorySearchEndDate").val(userPushHistorySearchEndDate).trigger("change");
}
/****************************************************************************
 * 정렬 이벤트
 ****************************************************************************/
function fn_alignEvent(param, param2){
    let align = "";

    if("A"==param){
        align = "오늘";

        fn_userPushHistorySetDate('A');
    }
    else if("B"==param){
        align = "최근30일";

        fn_userPushHistorySetDate('D');
    }
    else if("C"==param){
        align = "최근90일";

        fn_userPushHistorySetDate('E');
    }
    else if("D"==param){
        align = "이번주";

        fn_userPushHistorySetDate('C');
    }
    else if("E"==param){
        align = "이번달";

        fn_userPushHistorySetDate('F');
    }
    else if("F"==param){
        align = "올해";

        fn_userPushHistorySetDate('G');
    }
    else if("G"==param){
        align = "지난주";

        fn_userPushHistorySetDate('H');
    }
    else if("H"==param){
        align = "지난달";

        fn_userPushHistorySetDate('I');
    }
    else{
        align = "";
    }
    $("#userPushHistorySearchDateType").val(param);
    $("#userPushHistorySearchDateType").siblings("button").text(align);
}

function fn_formatAmount(amount){
    let data = typeof amount === 'number'?amount:amount.value;
    return data.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
/****************************************************************************
 * 초기화하기
 ****************************************************************************/
function fn_userPushHistoryReset(){
    fn_userPushHistorySetDate('D');
    $("#userPushHistorySearchDateType option:eq(0)").prop("selected", true);

    $("#userPushHistorySearchKeyword").val("");

    fn_userPushHistorySearch();
}

/****************************************************************************
 * 완료
 ****************************************************************************/
function fn_userPushHistoryOk(){
    fn_userPushHistoryReset();
}


function fn_detailPaymentPopup(param){
    let reqParam =  {
        "muPaymentId" : param
    };

    if("Y"==selectUseYn){
        // 수정가능
        paymentDetailModal.popup(function(obj, reqParam) {
            fn_userPushHistoryOk();
        }, reqParam);
    }

}

let userPushHistoryColumnDefs = [
    /*{ field: "checkbox", headerName:"", minWidth:55, maxWidth:55, headerCheckboxSelection: true, checkboxSelection: true },*/
    /* { field: "rowNum", headerName:"번호", minWidth:80,maxWidth:80, sortable: false }, */
    { field: "type", headerName:"알림구분", minWidth:130, maxWidth:130},
    { field: "sendDate", headerName:"전송일시", minWidth:130, maxWidth:130 },
    { field: "content", headerName:"내용", minWidth:200},
    { field: "popbillState", headerName:"전송상태", minWidth:130, maxWidth:130 }
];

// let the grid know which columns and what data to use
let userPushHistoryGridOptions = {
    suppressRowTransform: true,
    columnDefs: userPushHistoryColumnDefs,
    defaultColDef: {		// 리스트 기본 설정
        flex: 1,
        sortable: true,		//정렬 여부
        resizable: true,	//리사이즈
        editable: true,	// 그리드에서 데이터 수정
        cellStyle:{textAlign:'left',fontSize:'14px',padding:'0'},
        //suppressSizeToFit:true,		//자동 맞춤
        //enableRowGroup: true,		// 그룹 묶음
        enablePivot: true,
        enableValue : true
    },
    //suppressMultiSort:true,  //단일솔트 true가 단일, false가 다중 shift + sort 시
    headerHeight : 41, // header 높이
    rowHeight : 41, // row 높이
    rowData : userPushHistoryAgGridData,
    suppressRowClickSelection : true, // 로우 클릭시 체크박스 선택 true no, false yes
    localeText : {
        noRowsToShow : '조회 결과가 없습니다.'
    }, //데이터 없을 시 나오는 문구
    rowSelection : 'multiple', // row 다중 선택
    debug : false,
    onCellClicked: function(event){ //셀 클릭 이벤트
        /* alert(event.column.colId); */
        if('paymentCategoryItemName'==event.column.colId){
            fn_detailPaymentPopup(event.data.muPaymentId);
        }
    },
    onSelectionChanged: function(event){ //체크박스 선택
        let selectRows = [];
        selectRows = event.api.getSelectedRows();

        userPushHistorySelectId = '';
        for(let i=0; i<selectRows.length; i++){
            userPushHistorySelectId += selectRows[i].muPaymentId + ",";
        }
        userPushHistorySelectId = userPushHistorySelectId.substring(0, userPushHistorySelectId.lastIndexOf(','));
    },
    onSortChanged: function(event){
        //정렬
        userPushHistorySort = ''; //기존 정렬 초기화
        let columnArr = event.columnApi.getColumnState();
        if(0<columnArr.length){
            //sort index 순으로 재정렬
            columnArr.sort(function(a,b){
                return a.sortIndex - b.sortIndex;
            });

            let nullCnt = 0;
            for(let i=0; i<columnArr.length; i++){
                let gridSortModel = columnArr[i].colId;
                let gridSort = columnArr[i].sort;

                if(gridSort != null){
                    userPushHistoryStart = 0;
                    userPushHistorySort += gridSortModel+' '+ gridSort + ',';
                }
                else{
                    nullCnt++;
                    if(nullCnt == columnArr.length){
                        userPushHistorySort = '';
                        userPushHistoryDir = '';
                        userPushHistoryStart = 0;
                    }
                }
            }
        }
        userPushHistorySort = userPushHistorySort.substring(0,userPushHistorySort.lastIndexOf( ",")); //맨끝 콤마 지우기

        fn_userPushHistorySearch();
    }
};

// lookup the container we want the Grid to use
let userPushHistoryGridDiv = document.querySelector('#userPushHistoryGrid');

// create the grid passing in the div to use together with the columns & data we want to use
new agGrid.Grid(userPushHistoryGridDiv, userPushHistoryGridOptions);


/****************************************************************************
 * 검색 엔터 이벤트
 ****************************************************************************/
function fn_searchEnter(e, type){
    if(e.which){
        // 파이어폭스
        if(e.which==13) {
            //로그인 액션 스크립트
            fn_userPushHistorySearch();
        }
    }else{
        // 윈도우, 사파리, 크롬
        if(event.keyCode==13) {
            //로그인 액션 스크립트
            fn_userPushHistorySearch();
        }
    }
}


/****************************************************************************
 * 페이지 init
 ****************************************************************************/
function fn_pageInit(){
    /// 검색 기간 콤보 선택 이벤트
	let comboTarget = $("#userPushHistorySearchDateType");
	fn_setComboEvent(comboTarget, function(value){
		fn_userPushHistorySetDate(value);
	}, 'N');
	
	// 날짜 datepicker
	fn_searchDatePicker("#userPushHistorySearchStartDate", "#userPushHistorySearchEndDate");
	
	if(!userPushHistorySearchStartDate&&!userPushHistorySearchStartDate){
		// 기간검색 최근30일로 초기화
		$("#userPushHistorySearchDateType").next(".select_option_list").find("li:eq(1)").click();
	}
	else{
		$("#userPushHistorySearchStartDate").val(userPushHistorySearchStartDate).trigger("change");;
		$("#userPushHistorySearchEndDate").val(userPushHistorySearchEndDate).trigger("change");;
	}
	
	
	// 알림구분 콤보데이타 설정
	let comboTarget2 = $("#userPushHistorySearchType");
	fn_setComboEvent(comboTarget2, function(value){
	}, 'N');
	
    // 초기 페이징 처리
    $("#userPushHistorySearchKeyword").val(userPushHistorySearchKeywordParam);

    fn_userPushHistorySearch("A");
}

/****************************************************************************
 * 페이지 event
 ****************************************************************************/
function fn_pageEvent(){
    // 검색 input
	$(document).on('keypress', '#userPushHistorySearchKeyword', function(e) {
		fn_searchEnter(e);
	});

	// 검색 조회 버튼
	$("#btnSearchUserReserveHistory").click(function () {
		fn_userPushHistorySearch();
	});
	
    // 엑셀다운로드
    $("#btnDownloadUserPushHistoryExcel").click(function () {
        fn_downloadExcel();
    });
}

$(function(){
    // 페이지 event
    fn_pageEvent();
    // 페이지 init
    fn_pageInit();
});