<?php
declare(strict_types=1);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/conexao.php';
require_once __DIR__ . '/computadores_helpers.php';

date_default_timezone_set('America/Sao_Paulo');
if (compEhCynthia()) { compRedirecionar('dashboard_cynthia.php?acesso_restrito=1'); }
if (!$mysqli instanceof mysqli) { http_response_code(500); exit('Conexão indisponível.'); }
$mysqli->set_charset('utf8mb4');compGarantirEstrutura($mysqli);$csrf=compCsrf();$usuario=compUsuarioAtual()?:'Técnico autenticado';

if($_SERVER['REQUEST_METHOD']==='POST'){
    try{
        compValidarCsrf();$acao=compTexto($_POST['acao']??'',50);
        if($acao==='salvar_setor'){
            $nome=compTexto($_POST['nome']??'',150);if($nome==='')throw new RuntimeException('Informe o nome do setor.');
            $id=compObterOuCriarSetor($mysqli,$nome,compNulo($_POST['secretaria']??'',150),compNulo($_POST['predio']??'',150),compNulo($_POST['andar']??'',80));
            compFlash('sucesso','Setor criado ou atualizado.');compRedirecionar('mapa_computadores.php?setor_id='.$id);
        }
        if($acao==='salvar_ambiente'){
            $id=(int)($_POST['id']??0);$setorId=(int)($_POST['setor_id']??0);$nome=compTexto($_POST['nome']??'',150);
            if($setorId<=0||$nome==='')throw new RuntimeException('Informe setor e nome do ambiente.');
            $tipo=compTexto($_POST['tipo']??'SALA',50);$col=max(1,min(12,(int)($_POST['grid_coluna']??1)));$linha=max(1,min(30,(int)($_POST['grid_linha']??1)));$larg=max(1,min(12,(int)($_POST['grid_largura']??3)));$alt=max(1,min(6,(int)($_POST['grid_altura']??1)));$cor=compNulo($_POST['cor']??'',20);$obs=compNulo($_POST['observacoes']??'',500);
            if($id>0){$stmt=$mysqli->prepare("UPDATE ti_ambientes SET nome=?,tipo=?,grid_coluna=?,grid_linha=?,grid_largura=?,grid_altura=?,cor=?,observacoes=?,ativo=1 WHERE id=? AND setor_id=?");$stmt->bind_param('ssiiiissii',$nome,$tipo,$col,$linha,$larg,$alt,$cor,$obs,$id,$setorId);}else{$stmt=$mysqli->prepare("INSERT INTO ti_ambientes(setor_id,nome,tipo,grid_coluna,grid_linha,grid_largura,grid_altura,cor,observacoes,criado_por) VALUES(?,?,?,?,?,?,?,?,?,?)");$stmt->bind_param('issiiiisss',$setorId,$nome,$tipo,$col,$linha,$larg,$alt,$cor,$obs,$usuario);}
            if(!$stmt->execute()){ $erro=$stmt->error;$stmt->close();throw new RuntimeException('Não foi possível salvar o ambiente: '.$erro);}$stmt->close();compFlash('sucesso','Ambiente salvo no mapa.');compRedirecionar('mapa_computadores.php?setor_id='.$setorId);
        }
        if($acao==='mover_equipamento'){
            $id=(int)($_POST['computador_id']??0);$ambienteId=(int)($_POST['ambiente_id']??0);if($id<=0||$ambienteId<=0)throw new RuntimeException('Selecione o equipamento e o ambiente.');
            $mysqli->begin_transaction();$antigo=compCarregarComputador($mysqli,$id,true);if(!$antigo)throw new RuntimeException('Equipamento não encontrado.');
            $stmt=$mysqli->prepare("SELECT a.id,a.nome,a.setor_id,s.nome setor_nome FROM ti_ambientes a JOIN ti_setores s ON s.id=a.setor_id WHERE a.id=? AND a.ativo=1");$stmt->bind_param('i',$ambienteId);$stmt->execute();$amb=$stmt->get_result()->fetch_assoc();$stmt->close();if(!$amb)throw new RuntimeException('Ambiente não encontrado.');
            $local=compNulo($_POST['localizacao_texto']??'',180);$stmt=$mysqli->prepare("UPDATE ti_computadores SET setor_id=?,ambiente_id=?,localizacao_texto=?,atualizado_por=? WHERE id=?");$stmt->bind_param('iissi',$amb['setor_id'],$ambienteId,$local,$usuario,$id);$stmt->execute();$stmt->close();compRegistrarMovimentacao($mysqli,$id,'MOVIDO_NO_MAPA',$antigo['status'],$antigo['status'],$antigo['responsavel_nome'],$antigo['responsavel_nome'],$antigo['setor_nome'],$amb['setor_nome'],$antigo['ambiente_nome'],$amb['nome'],compNulo($_POST['motivo']??'Movimentação realizada pelo mapa interno.',500));$mysqli->commit();compFlash('sucesso','Equipamento movido no mapa com histórico registrado.');compRedirecionar('mapa_computadores.php?setor_id='.(int)$amb['setor_id'].'&destacar='.$id);
        }
        throw new RuntimeException('Ação inválida.');
    }catch(Throwable $e){try{$mysqli->rollback();}catch(Throwable){}compFlash('erro',$e->getMessage());compRedirecionar('mapa_computadores.php');}
}

$setores=[];$res=$mysqli->query("SELECT s.*,COUNT(c.id) total_equipamentos,COUNT(DISTINCT a.id) total_ambientes FROM ti_setores s LEFT JOIN ti_computadores c ON c.setor_id=s.id LEFT JOIN ti_ambientes a ON a.setor_id=s.id AND a.ativo=1 WHERE s.ativo=1 GROUP BY s.id ORDER BY s.nome");while($res&&$r=$res->fetch_assoc())$setores[]=$r;
$setorId=(int)($_GET['setor_id']??0);if($setorId<=0&&$setores)$setorId=(int)$setores[0]['id'];$destacar=(int)($_GET['destacar']??0);
$setorAtual=null;foreach($setores as $s){if((int)$s['id']===$setorId){$setorAtual=$s;break;}}
$ambientes=[];$equipamentos=[];
if($setorId>0){$stmt=$mysqli->prepare("SELECT a.*,COUNT(c.id) total_equipamentos FROM ti_ambientes a LEFT JOIN ti_computadores c ON c.ambiente_id=a.id WHERE a.setor_id=? AND a.ativo=1 GROUP BY a.id ORDER BY a.grid_linha,a.grid_coluna,a.ordem,a.nome");$stmt->bind_param('i',$setorId);$stmt->execute();$res=$stmt->get_result();while($r=$res->fetch_assoc())$ambientes[]=$r;$stmt->close();
$stmt=$mysqli->prepare("SELECT c.*,a.nome ambiente_nome FROM ti_computadores c LEFT JOIN ti_ambientes a ON a.id=c.ambiente_id WHERE c.setor_id=? AND c.status<>'BAIXADO' ORDER BY a.nome,c.tipo,c.patrimonio,c.nome_maquina");$stmt->bind_param('i',$setorId);$stmt->execute();$res=$stmt->get_result();while($r=$res->fetch_assoc())$equipamentos[]=$r;$stmt->close();}
$porAmbiente=[];$semAmbiente=[];foreach($equipamentos as $e){$aid=(int)($e['ambiente_id']??0);if($aid>0)$porAmbiente[$aid][]=$e;else$semAmbiente[]=$e;}
$stats=['total'=>count($equipamentos),'em_uso'=>0,'manutencao'=>0,'sem_responsavel'=>0,'sem_ambiente'=>count($semAmbiente)];foreach($equipamentos as $e){if($e['status']==='EM_USO')$stats['em_uso']++;if($e['status']==='MANUTENCAO')$stats['manutencao']++;if(empty($e['responsavel_nome']))$stats['sem_responsavel']++;}
$flash=compConsumirFlash();
?>
<!doctype html><html lang="pt-BR"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta name="theme-color" content="#08396f"><title>Mapa de Equipamentos | Manutenção TI</title><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet"><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet"><link href="computadores_style.css?v=1" rel="stylesheet"><style>.map-layout{display:grid;grid-template-columns:minmax(0,1fr) 330px;gap:14px;margin-top:14px}.map-panel,.map-sidebar{overflow:hidden;border:1px solid rgba(255,255,255,.92);border-radius:28px;background:rgba(255,255,255,.91);box-shadow:var(--shadow)}.map-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:17px 18px;border-bottom:1px solid var(--border);background:linear-gradient(180deg,#fff,#f8fbfd)}.map-toolbar h3{margin:0;font-size:15px;font-weight:950}.map-toolbar p{margin:4px 0 0;color:var(--muted);font-size:8px}.schematic-wrap{overflow:auto;padding:18px;background:radial-gradient(circle at 50% 0,rgba(23,100,173,.06),transparent 30rem),#edf3f8}.schematic{min-width:1040px;min-height:650px;display:grid;grid-template-columns:repeat(12,minmax(70px,1fr));grid-auto-rows:155px;gap:10px;padding:14px;border:1px solid #cddae5;border-radius:22px;background-image:linear-gradient(rgba(8,57,111,.045) 1px,transparent 1px),linear-gradient(90deg,rgba(8,57,111,.045) 1px,transparent 1px);background-size:26px 26px;background-color:#f8fbfd;box-shadow:inset 0 0 40px rgba(8,57,111,.05)}.room{position:relative;overflow:hidden;display:flex;flex-direction:column;padding:12px;border:2px solid #aac2d6;border-radius:18px;background:rgba(255,255,255,.95);box-shadow:0 12px 28px rgba(8,57,111,.09)}.room:before{content:"";position:absolute;inset:0 0 auto;height:6px;background:var(--room-color,#1764ad)}.room-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;padding-top:3px}.room-head strong{display:block;font-size:9px;font-weight:950}.room-head span{display:block;margin-top:3px;color:var(--muted);font-size:6.5px}.room-count{padding:5px 7px;border-radius:999px;color:var(--blue);background:#eaf4fc;font-size:6px;font-weight:900}.devices{display:flex;align-content:flex-start;gap:6px;flex-wrap:wrap;overflow:auto;margin-top:10px;padding-right:2px}.device{position:relative;width:calc(50% - 3px);min-height:58px;padding:8px;border:1px solid var(--border);border-radius:12px;color:var(--text);background:var(--soft);transition:.18s ease}.device:hover{color:var(--text);transform:translateY(-2px);background:#fff;box-shadow:0 8px 18px rgba(8,57,111,.1)}.device.highlight{border-color:var(--gold);background:#fff7e6;animation:mapPulse 1.5s ease-in-out infinite}.device strong{display:block;padding-right:17px;font-size:7px;line-height:1.35;font-weight:950}.device span{display:block;margin-top:3px;color:var(--muted);font-size:6px;line-height:1.35}.device i{position:absolute;top:7px;right:7px;color:var(--blue)}@keyframes mapPulse{50%{box-shadow:0 0 0 6px rgba(232,173,22,0)}}.empty-room{display:grid;place-items:center;flex:1;color:var(--light);font-size:7px;text-align:center}.unassigned{grid-column:1/span 12;min-height:120px;border-style:dashed;border-color:#d17a00;background:#fff9eb}.side-section{padding:16px;border-bottom:1px solid var(--border)}.side-section:last-child{border-bottom:0}.side-section h4{margin:0;font-size:10px;font-weight:950}.side-section p{margin:4px 0 0;color:var(--muted);font-size:7px;line-height:1.45}.side-kpis{display:grid;grid-template-columns:1fr 1fr;gap:7px;margin-top:11px}.side-kpi{padding:10px;border:1px solid var(--border);border-radius:13px;background:var(--soft)}.side-kpi strong{display:block;color:var(--blue);font-size:20px;font-weight:950}.side-kpi span{display:block;margin-top:4px;color:var(--light);font-size:6px;font-weight:900;text-transform:uppercase}.legend{display:flex;flex-direction:column;gap:7px;margin-top:10px}.legend span{display:flex;align-items:center;gap:7px;color:var(--muted);font-size:7px}.dot{width:10px;height:10px;border-radius:50%}.dot.use{background:#1769aa}.dot.available{background:#087f5b}.dot.maintenance{background:#5d46b5}.dot.alert{background:#bf263d}.map-select{min-height:43px;min-width:260px;padding:0 12px;border:1px solid var(--border);border-radius:13px;background:#fff;color:var(--text);font-size:8px;font-weight:800}.config-list{display:flex;flex-direction:column;gap:7px;margin-top:10px}.config-item{display:flex;align-items:center;justify-content:space-between;gap:9px;padding:10px;border:1px solid var(--border);border-radius:13px;background:var(--soft)}.config-item strong{display:block;font-size:8px}.config-item span{display:block;margin-top:3px;color:var(--muted);font-size:6.5px}@media(max-width:1100px){.map-layout{grid-template-columns:1fr}.map-sidebar{order:-1}.map-toolbar{align-items:flex-start;flex-direction:column}.map-select{width:100%;min-width:0}}@media(max-width:700px){.device{width:100%}.schematic-wrap{padding:8px}}</style></head><body><div class="top-strip"></div><div class="bg-grid"></div><div class="app"><header class="main-header"><div class="header-content"><div class="brand-area"><div class="logo-box"><img src="assets/logo_pref.jpg" alt="Prefeitura"></div><div><span class="eyebrow"><i class="bi bi-diagram-3-fill"></i>Mapa interno, não geográfico</span><h1 class="header-title">Mapa de Computadores</h1><p class="header-subtitle">Representação lógica de setores, salas e posições para localizar cada equipamento sem usar Google Maps.</p></div></div><nav class="header-actions"><a href="computadores.php" class="header-button primary"><i class="bi bi-pc-display"></i>Computadores</a><button class="header-button" data-bs-toggle="modal" data-bs-target="#modalSetor"><i class="bi bi-building-add"></i>Novo setor</button><button class="header-button" data-bs-toggle="modal" data-bs-target="#modalAmbiente" onclick="novoAmbiente()"><i class="bi bi-grid-3x3-gap-fill"></i>Novo ambiente</button><a href="listar_os.php" class="header-button"><i class="bi bi-arrow-left-circle-fill"></i>Ordens de serviço</a></nav></div></header><main class="main"><?php if($flash):?><div class="flash <?=$flash['tipo']==='sucesso'?'success':'error'?>"><i class="bi <?=$flash['tipo']==='sucesso'?'bi-check-circle-fill':'bi-exclamation-triangle-fill'?>"></i><?=compE($flash['mensagem'])?></div><?php endif;?>
<section class="hero"><div><h2>Escolha o setor e veja <span>onde cada equipamento está.</span></h2><p>Cada sala, recepção, gabinete, laboratório ou corredor vira uma área do mini mapa. Os equipamentos aparecem dentro do ambiente com patrimônio, responsável e posição exata.</p><div class="hero-tags"><span class="hero-tag"><i class="bi bi-building-fill"></i>Setores e prédios</span><span class="hero-tag"><i class="bi bi-door-open-fill"></i>Salas e ambientes</span><span class="hero-tag"><i class="bi bi-pc-display"></i>Equipamentos clicáveis</span><span class="hero-tag"><i class="bi bi-clock-history"></i>Mudança registrada</span></div></div><aside class="hero-side"><small>Setor selecionado</small><strong><?=compE($setorAtual['nome']??'Nenhum')?></strong><span><?=compE(trim(implode(' • ',array_filter([$setorAtual['secretaria']??'',$setorAtual['predio']??'',$setorAtual['andar']??''])))?:'Cadastre ou selecione um setor')?></span></aside></section>
<div class="map-layout"><section class="map-panel"><header class="map-toolbar"><div><h3>Planta lógica do setor</h3><p>As áreas são organizadas por colunas e linhas configuráveis.</p></div><form method="get"><select name="setor_id" class="map-select" onchange="this.form.submit()"><option value="0">Selecione o setor</option><?php foreach($setores as $s):?><option value="<?=(int)$s['id']?>" <?=$setorId===(int)$s['id']?'selected':''?>><?=compE($s['nome'])?> • <?=(int)$s['total_equipamentos']?> equipamento(s)</option><?php endforeach;?></select></form></header><div class="schematic-wrap"><div class="schematic">
<?php foreach($ambientes as $a):?><?php $eqs=$porAmbiente[(int)$a['id']]??[];$cor=$a['cor']?:'#1764ad';?><article class="room" style="--room-color:<?=compE($cor)?>;grid-column:<?=(int)$a['grid_coluna']?>/span <?=(int)$a['grid_largura']?>;grid-row:<?=(int)$a['grid_linha']?>/span <?=(int)$a['grid_altura']?>"><header class="room-head"><span><strong><?=compE($a['nome'])?></strong><span><?=compE($a['tipo'])?> • posição <?=(int)$a['grid_coluna']?>x<?=(int)$a['grid_linha']?></span></span><span class="room-count"><?=count($eqs)?> itens</span></header><?php if($eqs):?><div class="devices"><?php foreach($eqs as $e):?><?php [$tl,$ti]=compTipo($e['tipo']);?><a class="device <?=$destacar===(int)$e['id']?'highlight':''?>" href="computadores.php?buscar=<?=urlencode($e['patrimonio']?:$e['codigo_interno'])?>"><i class="bi <?=compE($ti)?>"></i><strong><?=compE($e['patrimonio']?:$e['nome_maquina']?:$e['codigo_interno'])?></strong><span><?=compE($e['responsavel_nome']?:'Sem responsável')?></span><span><?=compE($e['localizacao_texto']?:$tl)?></span></a><?php endforeach;?></div><?php else:?><div class="empty-room"><span><i class="bi bi-inbox"></i><br>Nenhum equipamento nesta área</span></div><?php endif;?></article><?php endforeach;?>
<?php if($semAmbiente):?><article class="room unassigned"><header class="room-head"><span><strong>Sem sala ou ambiente definido</strong><span>Equipamentos pertencem ao setor, mas precisam de localização detalhada.</span></span><span class="room-count"><?=count($semAmbiente)?> itens</span></header><div class="devices"><?php foreach($semAmbiente as $e):?><?php [$tl,$ti]=compTipo($e['tipo']);?><button class="device <?=$destacar===(int)$e['id']?'highlight':''?>" onclick='abrirMover(<?=json_encode($e,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP)?>)'><i class="bi <?=compE($ti)?>"></i><strong><?=compE($e['patrimonio']?:$e['nome_maquina']?:$e['codigo_interno'])?></strong><span><?=compE($e['responsavel_nome']?:'Sem responsável')?></span><span>Clique para mover</span></button><?php endforeach;?></div></article><?php endif;?>
<?php if(!$ambientes&&!$semAmbiente):?><div class="empty" style="grid-column:1/-1"><i class="bi bi-diagram-3"></i><strong>Mapa ainda vazio</strong><span>Cadastre ambientes e associe os equipamentos.</span></div><?php endif;?></div></div></section>
<aside class="map-sidebar"><section class="side-section"><h4>Resumo do setor</h4><p>Contagem apenas do setor selecionado.</p><div class="side-kpis"><div class="side-kpi"><strong><?=$stats['total']?></strong><span>Equipamentos</span></div><div class="side-kpi"><strong><?=$stats['em_uso']?></strong><span>Em uso</span></div><div class="side-kpi"><strong><?=$stats['manutencao']?></strong><span>Manutenção</span></div><div class="side-kpi"><strong><?=$stats['sem_ambiente']?></strong><span>Sem sala</span></div></div></section><section class="side-section"><h4>Legenda operacional</h4><div class="legend"><span><i class="dot use"></i>Em uso com responsável</span><span><i class="dot available"></i>Disponível</span><span><i class="dot maintenance"></i>Em manutenção</span><span><i class="dot alert"></i>Extraviado ou baixa</span></div></section><section class="side-section"><h4>Ambientes configurados</h4><p>Edite a posição de cada área na grade de 12 colunas.</p><div class="config-list"><?php foreach($ambientes as $a):?><div class="config-item"><span><strong><?=compE($a['nome'])?></strong><span>Col. <?=(int)$a['grid_coluna']?> • Linha <?=(int)$a['grid_linha']?> • <?=(int)$a['grid_largura']?>x<?=(int)$a['grid_altura']?></span></span><button class="action" onclick='editarAmbiente(<?=json_encode($a,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP)?>)'><i class="bi bi-pencil-fill"></i></button></div><?php endforeach;?></div></section></aside></div><footer class="page-footer"><span>Prefeitura de Extrema • Mapa interno de equipamentos<br>Não utiliza mapas externos nem dados de geolocalização.</span><span><i class="bi bi-shield-lock-fill"></i> Alterações ficam no histórico do equipamento</span></footer></main></div>
<div class="modal fade" id="modalSetor" tabindex="-1"><div class="modal-dialog modal-dialog-centered"><form method="post" class="modal-content"><div class="modal-header"><h5 class="modal-title"><i class="bi bi-building-add me-2"></i>Novo setor</h5><button class="btn-close btn-close-white" type="button" data-bs-dismiss="modal"></button></div><div class="modal-body"><input type="hidden" name="acao" value="salvar_setor"><input type="hidden" name="csrf_token" value="<?=compE($csrf)?>"><div class="form-grid"><div class="form-group full"><label>Nome do setor</label><input name="nome" class="control" required></div><div class="form-group full"><label>Secretaria</label><input name="secretaria" class="control"></div><div class="form-group"><label>Prédio / unidade</label><input name="predio" class="control"></div><div class="form-group"><label>Andar / bloco</label><input name="andar" class="control"></div></div></div><div class="modal-footer"><button class="modal-button" type="button" data-bs-dismiss="modal">Cancelar</button><button class="modal-button primary">Salvar setor</button></div></form></div></div>
<div class="modal fade" id="modalAmbiente" tabindex="-1"><div class="modal-dialog modal-lg modal-dialog-centered"><form method="post" class="modal-content"><div class="modal-header"><h5 class="modal-title"><i class="bi bi-grid-3x3-gap-fill me-2"></i>Configurar ambiente</h5><button class="btn-close btn-close-white" type="button" data-bs-dismiss="modal"></button></div><div class="modal-body"><input type="hidden" name="acao" value="salvar_ambiente"><input type="hidden" name="id" id="ambId"><input type="hidden" name="csrf_token" value="<?=compE($csrf)?>"><div class="form-grid"><div class="form-group span2"><label>Setor</label><select name="setor_id" id="ambSetor" class="control" required><?php foreach($setores as $s):?><option value="<?=(int)$s['id']?>" <?=$setorId===(int)$s['id']?'selected':''?>><?=compE($s['nome'])?></option><?php endforeach;?></select></div><div class="form-group"><label>Tipo</label><select name="tipo" id="ambTipo" class="control"><option value="SALA">Sala</option><option value="RECEPCAO">Recepção</option><option value="GABINETE">Gabinete</option><option value="LABORATORIO">Laboratório</option><option value="CORREDOR">Corredor</option><option value="ALMOXARIFADO">Almoxarifado</option><option value="OUTRO">Outro</option></select></div><div class="form-group span2"><label>Nome do ambiente</label><input name="nome" id="ambNome" class="control" required></div><div class="form-group"><label>Cor de destaque</label><input name="cor" id="ambCor" class="control" type="color" value="#1764ad"></div><div class="form-group"><label>Coluna inicial (1–12)</label><input name="grid_coluna" id="ambCol" class="control" type="number" min="1" max="12" value="1"></div><div class="form-group"><label>Linha inicial</label><input name="grid_linha" id="ambLinha" class="control" type="number" min="1" max="30" value="1"></div><div class="form-group"><label>Largura (1–12)</label><input name="grid_largura" id="ambLarg" class="control" type="number" min="1" max="12" value="3"></div><div class="form-group"><label>Altura (1–6)</label><input name="grid_altura" id="ambAlt" class="control" type="number" min="1" max="6" value="1"></div><div class="form-group full"><label>Observações</label><textarea name="observacoes" id="ambObs" class="control"></textarea></div></div></div><div class="modal-footer"><button class="modal-button" type="button" data-bs-dismiss="modal">Cancelar</button><button class="modal-button primary">Salvar no mapa</button></div></form></div></div>
<div class="modal fade" id="modalMover" tabindex="-1"><div class="modal-dialog modal-dialog-centered"><form method="post" class="modal-content"><div class="modal-header"><h5 class="modal-title"><i class="bi bi-geo-alt-fill me-2"></i>Mover equipamento</h5><button class="btn-close btn-close-white" type="button" data-bs-dismiss="modal"></button></div><div class="modal-body"><input type="hidden" name="acao" value="mover_equipamento"><input type="hidden" name="computador_id" id="moverId"><input type="hidden" name="csrf_token" value="<?=compE($csrf)?>"><div class="form-group"><label>Novo ambiente</label><select name="ambiente_id" class="control" required><option value="">Selecione</option><?php foreach($ambientes as $a):?><option value="<?=(int)$a['id']?>"><?=compE($a['nome'])?></option><?php endforeach;?></select></div><div class="form-group" style="margin-top:10px"><label>Posição exata</label><input name="localizacao_texto" class="control" placeholder="Mesa, bancada, lado da janela..."></div><div class="form-group" style="margin-top:10px"><label>Motivo</label><textarea name="motivo" class="control">Movimentação realizada pelo mapa interno.</textarea></div></div><div class="modal-footer"><button class="modal-button" type="button" data-bs-dismiss="modal">Cancelar</button><button class="modal-button primary">Confirmar mudança</button></div></form></div></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><script>const modalAmb=bootstrap.Modal.getOrCreateInstance(document.getElementById('modalAmbiente'));const modalMover=bootstrap.Modal.getOrCreateInstance(document.getElementById('modalMover'));function novoAmbiente(){document.getElementById('ambId').value='';document.getElementById('ambNome').value='';document.getElementById('ambTipo').value='SALA';document.getElementById('ambCor').value='#1764ad';document.getElementById('ambCol').value='1';document.getElementById('ambLinha').value='1';document.getElementById('ambLarg').value='3';document.getElementById('ambAlt').value='1';document.getElementById('ambObs').value=''}function editarAmbiente(a){document.getElementById('ambId').value=a.id;document.getElementById('ambSetor').value=a.setor_id;document.getElementById('ambNome').value=a.nome||'';document.getElementById('ambTipo').value=a.tipo||'SALA';document.getElementById('ambCor').value=a.cor||'#1764ad';document.getElementById('ambCol').value=a.grid_coluna||1;document.getElementById('ambLinha').value=a.grid_linha||1;document.getElementById('ambLarg').value=a.grid_largura||3;document.getElementById('ambAlt').value=a.grid_altura||1;document.getElementById('ambObs').value=a.observacoes||'';modalAmb.show()}function abrirMover(e){document.getElementById('moverId').value=e.id;modalMover.show()}</script><script src="alerta_global_cliente.js?v=7"></script></body></html>