package com.sh.djpk.econsole.ui.controller.konsolidasi;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sh.djpk.econsole.ui.controller.HeaderTemplate;
import com.sh.djpk.econsole.ui.controller.managementdata.DataKonsolidasiCtl;
import com.sh.djpk.share.dto.periodeDto;
import com.sh.djpk.share.model.RestResponse.HttpMethod;
import com.sh.djpk.share.util.ClientsUtil;

@ManagedBean
@ViewScoped
public class AkunEliminasi {
	
	public static final Logger LOGGER = LoggerFactory
			.getLogger(DataKonsolidasiCtl.class);
	private static final long serialVersionUID = 1L;
	
	HashMap<String, Object> data = new HashMap<String, Object>();
	public List<Map<String, Object>> mapAkun;
	HashMap<String, Object> params = new HashMap<String, Object>();
	
	List<Map<String, Object>> selectOneHeader = new ArrayList<Map<String, Object>>();
	String selectedHeader;
	
	@PostConstruct
    public void init() {
		
//		List<Map<String, Object>> 
		int thn = getSessionTahunAnggaran();
		mapAkun = ClientsUtil.callWsListResponse(
				"/akuneliminasi/tahun/"+ String.valueOf(thn), null, HttpMethod.GET,
				null);
//		System.out.println("========================================="+mapAkun);
		
//		for (Map<String, Object> mpl : lst){
//			period.add(new periodeDto(mpl.get("id").toString(),mpl.get("name").toString()));
//		}
		selectOneHeader = getDataHeader();
		
		
	}
	
	public Integer getSessionTahunAnggaran() {
		HttpServletRequest request = (HttpServletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest();
		HttpSession session = request.getSession(true);
		HeaderTemplate hdrT = (HeaderTemplate) session
				.getAttribute("headerTemplate");
		Integer i = hdrT.getTahunAnggaran();
		return i;
	}
	
	public String add() throws IOException {
		LOGGER.info("<<ADD>>");
		this.data = new HashMap<String, Object>();
//		valueButtonSimpan = "Simpan";
		params.put("action", "ADD");
		return doToDetail();
	}
	
	public String doToDetail() throws IOException {
		LOGGER.info("<<doToDetail>>");

		// selectOnePemda = getDataSelectPemda();
		// selectOneKdUser = getDataSelectKdUser();
		// selectOneAuthItem = getDataAuthItem();
		// Map<String,Object> options = new HashMap<>();
		// options.put("resizable", false);
		// PrimeFaces.current().dialog().openDynamic("_detail", options, null);

		// FacesContext.getCurrentInstance().getExternalContext().redirect("_detail.xhtml");
		return "_detail";
	}
	
	public List<Map<String, Object>> getDataHeader() {
		List<Map<String, Object>> l = ClientsUtil.callWsListResponse(
				"/akuneliminasi/head", null, HttpMethod.GET,
				null);
		return l;
	}
	
	public String proses() throws Exception {
		
		
		
		
		return "_index";
		
	}

	public List<Map<String, Object>> getMapAkun() {
		return mapAkun;
	}

	public void setMapAkun(List<Map<String, Object>> mapAkun) {
		this.mapAkun = mapAkun;
	}

	public HashMap<String, Object> getData() {
		return data;
	}

	public void setData(HashMap<String, Object> data) {
		this.data = data;
	}

	public HashMap<String, Object> getParams() {
		return params;
	}

	public void setParams(HashMap<String, Object> params) {
		this.params = params;
	}

	public List<Map<String, Object>> getSelectOneHeader() {
		return selectOneHeader;
	}

	public void setSelectOneHeader(List<Map<String, Object>> selectOneHeader) {
		this.selectOneHeader = selectOneHeader;
	}

	public String getSelectedHeader() {
		return selectedHeader;
	}

	public void setSelectedHeader(String selectedHeader) {
		this.selectedHeader = selectedHeader;
	}

	
	
}
