/* RENDERIZAÇÂO */

function montar_page(){
	var a = window.localStorage.getItem('user');
	var atual_page = window.localStorage.getItem('atual_page');
		
	if( a != null){
		$("#ip-user").html(a);
		
		switch(atual_page) {
			  case "DASHBOARD":
					var rec = window.localStorage.getItem('recarga');
					var page     = dashboard_render();
					var nav_page = nav_top();
					
						render_page(nav_page,page);
						$("#ip-user").html(a);
						$("#ip-status").html(rec);
						lisPedidos();
				break;
			  case "PEDIDOS":
					var chave = window.localStorage.getItem('PEDIDO_COD');
					var page     = pedido_render();
					var nav_page = nav_top();
					
					render_page(nav_page,page);
					
					UNDPedido(chave);
					$("#ip-user").html(a);
					localStorage.setItem("pedido_atual",chave);
				
				break;		 
			  case "DETALHE":
					var chave = window.localStorage.getItem('ITEM_COD');
					var page     = detalhe_render();
					var nav_page = nav_top();
					
					render_page(nav_page,page);
					$("#ip-user").html(a);
					UNDItem(chave);
					$('#num').focus();
				
				break;
			  case "DETALHE_2":
					var page     = detalhe_render();
					var nav_page = nav_top();
					
					render_page(nav_page,page);
					$("#ip-user").html(a);
					UNDItemMOD();
					$('#num').focus();
				
				break;
			  case "LOGIN":
					var page = login_render();
					var nav_page = "";
					
					render_page(nav_page,page);			  
				break;
			  default:
					var page = login_render();
					var nav_page = "";
					
					render_page(nav_page,page);
				break;
		}
		
	
		
	}else{
		var page = login_render();
		var nav_page = "";
		render_page(nav_page,page);
	}
}

function render_page(nav,page){
		$("#app-render-nav").html(nav);
		$("#app-render").html(page);	
}

function register_page(page,cod){
		switch(page) {
			  case "DASHBOARD":
				window.localStorage.setItem("atual_page", "DASHBOARD");
				montar_page();
				
				break;
			  case "PEDIDOS":
				window.localStorage.setItem("atual_page", "PEDIDOS");
				window.localStorage.setItem("PEDIDO_COD", cod);
				montar_page();
				
				break;
			  case "DETALHE":
					window.localStorage.setItem("atual_page", "DETALHE");
					window.localStorage.setItem("ITEM_COD", cod);
					montar_page();
				
				break;
  			  case "DETALHE_2":
					window.localStorage.setItem("atual_page", "DETALHE_2");
					montar_page();				
				break;
		}
}


function nav_top(){
	var page = "";
	
	page += "    <nav class='navbar navbar-light bg-dark'>";
	page += "	  <a class='navbar-brand' href='#'>Mob Unidos</a>";
	page += "	  <a href='#' onclick='deslogar();' class='pull-right' style='color: #fff'><span id='ip-user'>User</span> <img src='img/salir.png' width='20' /></a>"; 
	page += "	</nav>";
	
	return page;
}

function login_render(){
	var page = "";
	

	
	page += "<div class='container'>";
	
    page += "  <div class='row justify-content-center'>";
    page += "    <div class='col-xs-10 col-sm-6 col-md-5 col-lg-4 text-center' style='margin-top: 5%;' >";

    page += "         <a href='login'><img src='img/icon.png' width='40%' style='padding-bottom: 10px;padding-top: 10px;' /></a>";
          
    page += "      <div class='card card-light box-shadow'>";
    page += "        <div class='card-heading text-center' style='padding: 10px;'>";
    page += "        </div><!--.card-heading-->";

    page += "        <div class='card-body'>";
    page += "           <form method='POST' id='form_login' onsubmit='return false;'>";
                
	page += "				<div class='form-group'> ";
	page += "					  <div class='input-group'>";
	page += "						<div class='input-group-addon'><i class='glyphicon glyphicon-envelope'></i></div>";
	page += "						<input type='hidden' name='POST_paramentro' id='POST_paramentro' value='LOG' />";
	page += "						<input type='hidden' name='cod' id='cod' value='1' />";
	page += "						<input type='text' name='user' id='user' class='form-control' placeholder='Usuário'>";
	page += "					  </div>";
	page += "				</div>";

	page += "				<div class='form-group'>";
	page += "					  <div class='input-group'>";
	page += "						<div class='input-group-addon'><i class='glyphicon glyphicon-lock'></i></div>";
	page += "						<input type='password' name='password' id='password' class='form-control' placeholder='Senha' current-password>";
	page += "					  </div>";
	page += "				</div>";
                    
	page += "				<div class='form-group'>";
    page += "                    <button type='button' onclick='login();' id='btn_form_MOB' class='btn btn-block btn-primary' name='btn-loginMOB'>Entrar</button>";
    page += "                    <div class='alerta d1'>";
    page += "                        <span id='text_erro'></span>";
    page += "                        <i class='far fa-times-circle' id='ic_close'></i>";
    page += "                    </div>";
	page += "				</div>";
                    
    page += "           </form>";
    page += "        </div>";
    page += "      </div><!--.card-->";
    page += "    </div><!--.cols-->";
    page += "  </div><!--.row-->";
	page += "  <div class='row justify-content-center'>";
    page += " 	  <div class='col-xs-10 col-sm-6 col-md-5 col-lg-4 text-center'>";
	page += "		  <p>Unidos Importados - Todos direitos resevados</p>";
	page += "	  </div>";
	page += "  </div>";
	  
    page += "</div><!--.container--> ";
	
	return page;
	
}

function dashboard_render(){
		var page = "";
		
		page += "<style>";
		page += ".card-light{ padding: 10px; }";
		page += ".table { margin-bottom: 1px;}";
		page += ".table td, .table th {";
		page += "	padding: 0 0px !important ";
		page += "	height: 30px !important;";
		page += "}";
		page += ".card-title{ font-size: 15px !important; }";
		page += ".card-text{ margin-bottom: 5px; }";
		page += "</style>";

		page += "<div class='container'>";
		page += "<div class='row'>";
		page += "	<div class='col-lg-12 text-center' style='padding: 10px;' >";
		page += "		 <p id='ip-status'>ÚLTIMA RECARGAR 06/07/2021 15:15</p>";
		page += "	</div>";
		page += "</div>";
		page += "<div class='row'>";
		page += "	<div class='col-lg-12 text-center' >";
		page += "		<button class='btn btn-info' onclick='showConfirm1();' >RECARREGAR</button>";
		page += "		<button class='btn btn-info' onclick='showTransfer();'>TRANSFERIR</button>";
		page += "	</div>";
		page += "</div>";
		page += "<hr>";
		page += "<div class='row'>";
		page += "	<div class='col-lg-12 text-center' >";
		page += "		 <b>PEDIDOS PENDENTES / NÃO TRANSFERIDOS</b>";
		page += "		 <div class='row'>";
		page += "		 	<div class='col-lg-12'>";
		page += "				<div id='result_pen'></div>";
		page += "			</div>";
		page += "		 </div>";
		page += "	</div>";
		page += "</div>";
		page += "<hr>";
		page += "<div class='row'>";
		page += "	<div class='col-lg-12 text-center' >";
		page += "		 <b>PEDIDOS CONCLUÍDOS</b>";
		page += "		 <div class='row'>";
		page += "		 	<div class='col-lg-12'>";
		page += "				<div id='result_con'></div>";
		page += "			</div>";
		page += "		 </div>";		 
		page += "	</div>";
		page += "</div>";
		page += "<br>";
		page += "<br>";
		page += "<br>";
		page += "<br>";
		page += "</div><!--.container--> ";
	
		return page;
}

function pedido_render(){
		var page = "";
		
			page += "<style>";
			page += "	.card-light{ padding: 10px; }";
			page += "	#ip-user{ padding-right: 5px; }";
			page += "	.btn{padding: .65rem 3.4rem;}";
			page += "	.card{ margin: 0px;}";
				
			page += "	.table { margin-bottom: 1px;}";
			page += "	.table td, .table th {";
			page += "		padding: 10px 0px !important;";
			page += "		height: 30px !important;";
			page += "	}";
			page += "	.card-title{ font-size: 15px !important; }";
			page += "	.card-text{ margin-bottom: 5px; }";
			page += "</style>";
		
			page += "		<div class='container'>";
			page += "			<div class='row'>";
			page += "				<div class='col-lg-12' >";
			page += "					<div id='result_ped_item'></div>";
			page += "					 <div class='row' style='padding-bottom: 50px'>";
			page += "						<div class='col-lg-12'>";
			page += "							<div class='card text-left'>";
			page += "							  <div class='card-body'>";
			page += "									<table class='table'>";
			page += "									  <thead>";
			page += "										<tr>";
			page += "										  <th scope='col'>Descrição</th>";
			page += "										  <th scope='col' style='width: 30px;text-align: center;'>Dep</th>";
			page += "										  <th scope='col' style='width: 30px;text-align: center;'>Sug</th>";
			page += "										  <th scope='col' style='width: 30px;text-align: center;'>Até</th>";
			page += "										</tr>";
			page += "									  </thead>";
			page += "									  <tbody id='id-pedidos'></tbody>";
			page += "									</table>";
			page += "							  </div>";
			page += "							</div>";
			page += "							<a href='javascript:void(0);' onclick=\"register_page('DETALHE_2','')\" class='btn btn-success btn-block'>BIP ALEATÓRIO</a>";
			page += "							<a href='javascript:void(0);' onclick='showConfirm();' class='btn btn-primary btn-block'>VOLTAR</a>";
			page += "						</div>";
			page += "					 </div>";
			page += "				</div>";
			page += "			</div>";
			page += "		</div><!--.container--> ";
		
		
		return page;
}

function detalhe_render(){
		var page = "";
		
		page += "<style>";
		page += ".card-light{ padding: 10px; }";
		page += "#ip-user{ padding-right: 5px; }";
		page += "<!--.btn{padding: .65rem 3.4rem;}-->";
		page += ".card{ margin: 20px;}";
		page += ".table { margin-bottom: 1px;}";
		page += ".table td, .table th {";
		page += "	padding: 10px 0px !important;";
		page += "	height: 30px !important;";
		page += "}";
		page += ".card-title{ font-size: 15px !important; }";
		page += ".card-text{ margin-bottom: 5px; }";
		page += "b{ font-size: 20px; font-transform: uppercase;}";
		page += "#myAudio{ display: none; }";
		page += "</style>";
		
		page += "<div class='container'>";
		page += "<div class='row' style='padding-top: 10px;'>";
		page += "	<div class='col-lg-12 text-center'>";
		page += "		<div id='item-one'></div>";
		page += "	</div>";
		page += "</div>";
		page += "<audio id='myAudio'>";
		page += "  <source src='js/beep-02.mp3' type='audio/mpeg'>";
		page += "  Your browser does not support the audio element.";
		page += "</audio>";
		page += "</div><!--.container--> ";
		
		return page;
}