<?php
//require_once("config/config_dir_raiz.php");
//include_once("cabecalho.php");
//include_once("rodape.php");
//include_once("nav_bar.php");
//$config = new Config();
//require_once($config->diretorio_raiz()."/src/model/bd/BiDAO.php");
//$biDAO = new BiDAO();
//$listaRelatorios = $biDAO->monta_filtro(2, "formDadosbi_analiseFiltro", "seletor1");
//$listaRelatorios = $biDAO->monta_filtro(1, "formDadosbi_analiseFiltro2", "seletor2");

?>

<style>
	.draggable {
    cursor: move;
}
.resizable {
    border: 1px dashed #88a1d3;
    position: relative;
    min-height: 50px;
}
.ui-resizable-handle {
    width: 10px;
    height: 10px;
    background-color: #ffffff;
    border: 1px solid #88a1d3;
    position: absolute;
}
.ui-resizable-nw {
    left: -5px;
    top: -5px;
    cursor: nw-resize;
}
.ui-resizable-ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}
.ui-resizable-sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}
.ui-resizable-se {
    bottom: -5px;
    right:-5px;
    cursor: se-resize;
}
.ui-resizable-n {
    top: -5px;
    left:50%;
    cursor: n-resize;
}
.ui-resizable-s {
    bottom: -5px;
    left: 50%;
    cursor: s-resize;
}
.ui-resizable-w {
    left:-5px;
    top:calc(50% - 5px);
    cursor: w-resize;
}
.ui-resizable-e {
    right:-5px;
    top:calc(50% - 5px);
    cursor: e-resize;
}
</style>

<div id="analies_capa" style="min-height: 100%; width: 100%; position: absolute; max-width: 925px; margin: 0 auto; background-color: white;   left: 0; right: 0; margin: auto;"></div>


<div class="modal" id="modalAddAnalise" style="z-index: 99999;" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Escolha uma análise</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" style="width: 100%; ">
        <div class='filtroForm' style="width: 100%; ">
			<label><span class="form_obrigatorio">*</span>Análise</label>
			<select style="width: 100%;" class="form" name="analise" id="analise" placeholder="Análise"    required   >
				<option value=""></option>
			   <?php foreach ($listaAnalise  as $umRegistroNome){ ?>
						<option value="<?php echo  $umRegistroNome->getCodigo(); ?>" <?php echo  $umRegistroNome->getCodigo(); ?>><?php echo $umRegistroNome->getCodigo()." - ".$umRegistroNome->getNome(); ?></option>
			   <?php } ?>
			</select>
		</div> 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" onclick="adiciona_analise({width: ''});" data-dismiss="modal">Adicionar</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Sair</button>
      </div>
    </div>
  </div>
</div>
<div class="modal" id="modalLink" style="z-index: 99999;" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Informe un link para redirecionamento</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" style="width: 100%; ">
        <div class='filtroForm' style="width: 100%; ">
			<label><span class="form_obrigatorio">*</span>Link</label>
			<input class="form" id="linkExterno" value="<?php echo trim($bi_pagina->getLink_externo());?>"/>
		</div> 
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary"  data-dismiss="modal">Adicionar</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Sair</button>
      </div>
    </div>
  </div>
</div>
<script src="js/pagina_form_admin.js"></script>
<script>
	
	$(document).ready(function() {
		$("#analise").select2();
	});
	listaAnaliseAdicionada =[];
	listaTodasAnalises =[];
	listaLabelAdicionadas = [];
	<?php foreach ($listaAnalise  as $umRegistroNome){ ?>
		listaTodasAnalises.push({codigo: '<?php echo  $umRegistroNome->getCodigo(); ?>', nome: "<?php echo  $umRegistroNome->getNome(); ?>", tipo: "<?php echo  $umRegistroNome->getGrafico()->getTipo_js(); ?>"});			
	<?php } ?>
	
	
	
	html = "";
	
	html += '<div  style="position: relative;  min-height: 70px; float: left; position: relative; padding-left: 5px; padding-right: 5px; z-index: 9999; ">';
	html += '<div class=\'\' style="width: 100px; float: left;" >';
	html += '	<label>Código</label>';
	html += '	<input type="text" readonly class="form" name="codigo" id="codigo" placeholder="Código"  value="<?php echo $bi_pagina->getCodigo();?>" valueDefault="<?php echo $bi_pagina->getCodigo();?>"  />';
	html += '</div> ';
	
	html += '<div class=\'\' style="float: left;">';
	html += '	<label><span class="form_obrigatorio">*</span>Nome</label>';
	html += '	<input type="text" class="form" name="nome" id="nome" placeholder="Nome"    required value="<?php echo $bi_pagina->getNome();?>" valueDefault="<?php echo $bi_pagina->getNome();?>"  />';
	html += '</div> ';

	html += '<div id=\'classarea\' style="float: left; position: relative; z-index: 9999; width: 150px;" >';
	html += '	<label><span class="form_obrigatorio">*</span>Area</label>';
	html += '	<select  class="form" name="area" id="area" placeholder="Area"    required value=\'<?php echo  $bi_pagina->getArea()->getCodigo();?>\' valueDefault=\'<?php echo  $bi_pagina->getArea()->getCodigo();?>\'  >';
	html += '		<option value=""></option>';
					<?php foreach ($listaArea  as $umRegistroNome){ ?>
	html += '				<option value=\'<?php echo  $umRegistroNome->getCodigo(); ?>\'><?php echo $umRegistroNome->getNome(); ?></option>';
					<?php } ?>
 	html += '	</select>';
	html += '</div> ';
	html += '</div> ';
	
	
	html += '<div style="position: relative; border-left: solid 1px #d9d9d9;  min-height: 70px;  float: left;  padding-left: 5px; padding-right: 5px; z-index: 9998;">';
	html += '<div class=\'\' style="float: left;">';
	html += '<label>Adicionar: </label> <p style="margin-top: -4px; width: 100%; position: relative; display: table"/>';
	html += '	<a href="javaScript: void(0);" class="btnSuccess btnSn form" data-toggle="modal" data-target="#modalAddAnalise">Dash <i class="fa-solid fa-table" style=" color: #67747e;"></i></a>';
	html += '	<a href="javaScript: void(0);" onclick="adicionarLabelText({width: \'\'}, \'texto\');" class="btnSuccess btnSn form" >Texto <i class="fa-solid fa-text-width" style=" color: #67747e;"></i></a>';
	html += '	<a href="javaScript: void(0);" onclick="adicionarLabelText({width: \'\'}, \'label\');" class="btnSuccess btnSn form" >Label <i class="fa-solid fa-tag" style=" color: #67747e;"></i></a>';
	html += '	<a href="javaScript: void(0);" onclick="adicionarLabelText({width: \'\'}, \'container\');" class="btnSuccess btnSn form" >Cont <i class="fa-solid fa-box" style=" color: #67747e;"></i></a>';
	html += '	<a href="javaScript: void(0);" class="btnSuccess btnSn form" data-toggle="modal" data-target="#modalLink" >Link <i class="fa-solid fa-link"></i></i></a>';
	
	html += '</div>';
	html += '</div> ';
	
	html += '<div id="classlayout" style="position: relative; border-left: solid 1px #d9d9d9;  min-height: 70px;  float: left;  padding-left: 5px; padding-right: 5px; z-index: 9997;">';
	html += '<label>Layout: </label> <p style="margin-top: -8px; width: 100%; position: relative; display: table"/>';
	html += '<select class="form" name="layout" id="layout" onchange="obs_rodape_pagina()" placeholder="Layout" required="" value="<?php echo  $bi_pagina->getLayout();?>" valuedefault="<?php echo  $bi_pagina->getLayout();?>">	';	
	html += '	<option value="responsivel" selected="selected">Responsível</option>	';			
	html += '	<option value="estatico">Estático</option>	';
	html += '</select>';
	html += '</div> ';
	
	html += '<div style="position: relative; border-left: solid 1px #d9d9d9;  min-height: 70px;  float: left;  padding-left: 5px; padding-right: 5px; z-index: 9996;">';
	html += '<div class=\'\' >';
	html += '<label></label> <p style="margin-top: -4px; width: 100%; position: relative; display: table"/>';
	html += '	<a href="javaScript: void(0)" class="btnSuccess btnSn" style="color: green;" onclick="finalizar_pagina()">Finalizar</a>';
	html += '</div>';
	html += '</div> ';
	
	$("#modaleditarbi_pagina_header").html(html);
	$('#area option[value=\'<?php echo  $bi_pagina->getArea()->getCodigo();?>\']').attr('selected','selected');
	$('#layout option[value=\'<?php echo  (empty($bi_pagina->getLayout()) ? "responsivel" : $bi_pagina->getLayout());?>\']').attr('selected','selected');
	obs_rodape_pagina();
	//percorer analises ja incluídas 
	<?php 
	echo "$( document ).ready(function() {";
	foreach ($listabi_pagina_analise  as $pagina_analise){ 
	echo "pagina_analise = {
		width: ".round($pagina_analise->getLargura()).", 
		height: ".round($pagina_analise->getAltura()).", 
		linha: ".round($pagina_analise->getLinha()).", 
		coluna: ".round($pagina_analise->getColuna()).", 
		top: ".round($pagina_analise->getTop_fixo()).", 
		left: ".round($pagina_analise->getLeft_fixo()).", 
		analise: \"".$pagina_analise->getAnalise()->getCodigo()."\", 
		pagina_analise: ".$pagina_analise->getCodigo().", 
		tipo: \"".$pagina_analise->getTipo()."\", 
		tipo_charts: '".($pagina_analise->getAnalise()->getGrafico()  !== null ? $pagina_analise->getAnalise()->getGrafico()->getCodigo() : "")."', 
		texto: \"".str_replace('"',"\\\"",str_replace("\n","",$pagina_analise->getTexto()))."\"};";
	 if($pagina_analise->getTipo() == "" or $pagina_analise->getTipo() == "analise")
		{
			echo " adiciona_analise(pagina_analise);";
		}
		else
		{
			echo " adicionarLabelText(pagina_analise, '".$pagina_analise->getTipo()."');";
		}	
	} 
	echo "});";
	  ?>
	
	html = "<button style='position: absolute; left: calc(100% - 30px); top: 30px;' onclick='zoon_analise(false)'><i class='fa-solid fa-magnifying-glass-plus'></i></button>";
	html += "<button style='position: absolute; left: calc(100% - 30px); top: 60px;' onclick='zoon_analise(true)'><i class='fa-solid fa-magnifying-glass-minus'></i></button>";
	$("#modal_conteudobi_pagina").append(html);
	
	ajustaAnalisesParaFicarNoTopoAoclicar();
	
	setTimeout(function(){
			$("#classarea").css("width", "150px");
			$("#classlayout").css("width", "150px");
			},200)
	
	
</script>



