class DetailsPanel {
	constructor() {
		this._iFrame = null;
	}
	
	get iFrame() {
		this._iFrame = document.getElementById("detailsIframe");
		this._iFrame.contentWindow.TheLastApp = TheLastApp;
		return this._iFrame;
	}
	set iFrame(newValue) {
		this._iFrame = newValue;
	}
	
	init(controller) {
		
		if (controller != null) {
			this.controller = controller;

//			this.controller._eventSupport.addEventListener("select",this,this.renderSomething);
		
		}
		return this;
	}
	
	
	select(item) {
		console.log(item);
		this.controller.selectedItem = item;
		this.controller._eventSupport.getEvent("select").fire(this,item);
		
		var type = this._processType(item);
		
		
		Structr.find("Page", null, {"name":type+"Details"}, this._processFindPageResponse.bind(this))
		
	}
	
	_processFindPageResponse(response) {
		console.log(response);

		var item = this.controller.selectedItem;
		
		var page = response.result.pop();

		var model = this.detailsPanel.model;
		
		if(page == null)
			model.properties.url = "/DefaultDetails";
		else
			model.properties.url = "/"+page.name;
	}
	
	
	_processType(item) {
		if (item == null)
			return "";
		
		var type = null;
		if (item.type != null)
			type = item.type;
		
//		if (type === "_schema")
//			type = "StructrSchema";
//			type = item.name;
		
		if (type == null) {
			type = item.constructor.name;
		}		
		
		if (type == null) {
			type = "";
		}

		return type;
	}
	
	
	renderSomething(event,data) {
		var This = event.target;
		
	}
	
}