<script>
document.addEventListener('DOMContentLoaded',function(){
  if(new URLSearchParams(location.search).get('folder')==='1'){const el=document.getElementById('fwpe-folder-panel');if(el){el.scrollIntoView({behavior:'smooth',block:'start');el.style.boxShadow='0 0 0 3px rgba(41,79,143,.24)';}}}
  const modal=document.getElementById('fwpe-front-editor'); if(!modal)return;
  const canvas=document.getElementById('fwpe-front-canvas'),ctx=canvas.getContext('2d'),note=document.getElementById('fwpe-front-note');
  let img=new Image(),original=new Image(),evId=0,mode='mark',rect=null,start=null,scale=1;
  function fit(){if(!original.src)return;const maxW=980,ratio=Math.min(1,maxW/original.naturalWidth);canvas.width=Math.round(original.naturalWidth*ratio);canvas.height=Math.round(original.naturalHeight*ratio);scale=ratio;draw();}
  function draw(){if(!canvas.width)return;ctx.clearRect(0,0,canvas.width,canvas.height);ctx.drawImage(img,0,0,canvas.width,canvas.height);if(rect){ctx.save();ctx.strokeStyle='#FFD400';ctx.lineWidth=Math.max(4,canvas.width/220);ctx.fillStyle='rgba(255,212,0,.18)';ctx.fillRect(rect.x,rect.y,rect.w,rect.h);ctx.strokeRect(rect.x,rect.y,rect.w,rect.h);ctx.restore();}}
  function pos(e){const r=canvas.getBoundingClientRect();return{x:(e.clientX-r.left)*(canvas.width/r.width),y:(e.clientY-r.top)*(canvas.height/r.height)}}
  function cropApply(){if(!rect||rect.w<10||rect.h<10)return;const tmp=document.createElement('canvas');tmp.width=Math.max(1,Math.round(rect.w/scale));tmp.height=Math.max(1,Math.round(rect.h/scale));tmp.getContext('2d').drawImage(img,rect.x/scale,rect.y/scale,rect.w/scale,rect.h/scale,0,0,tmp.width,tmp.height);const ni=new Image();ni.onload=function(){img=ni;original=ni;rect=null;fit();mode='mark';note.textContent='Recorte aplicado. Ahora marca el equipo reparado.'};ni.src=tmp.toDataURL('image/jpeg',.92)}
  canvas.addEventListener('pointerdown',e=>{if(!img.src)return;start=pos(e);rect=null;canvas.setPointerCapture(e.pointerId)});
  canvas.addEventListener('pointermove',e=>{if(!start)return;const p=pos(e);rect={x:Math.min(start.x,p.x),y:Math.min(start.y,p.y),w:Math.abs(start.x-p.x),h:Math.abs(start.y-p.y)};draw()});
  canvas.addEventListener('pointerup',()=>{start=null});
  document.getElementById('fwpe-front-crop').onclick=()=>{mode='crop';note.textContent='Modo recorte: dibuja el área que quieres conservar y después pulsa “Marcar equipo”.'};
  document.getElementById('fwpe-front-mark').onclick=()=>{if(mode==='crop'&&rect)cropApply();mode='mark';note.textContent='Modo marcar: dibuja un rectángulo amarillo sobre el equipo reparado.'};
  document.getElementById('fwpe-front-reset').onclick=()=>{img=original;rect=null;fit();mode='mark';note.textContent='Imagen restablecida.'};
  document.getElementById('fwpe-front-editor-close').onclick=()=>modal.style.display='none';
  document.querySelectorAll('.fwpe-photo-section .fwpe-edit-evidence').forEach(btn=>btn.addEventListener('click',function(){evId=this.dataset.id;const src=this.closest('.fwpe-photo-card').querySelector('img').src;original.src=src;original.onload=function(){img=original;fit();modal.style.display='flex';note.textContent='Puedes recortar o marcar la fotografía.'}}));
  document.getElementById('fwpe-front-save').onclick=()=>{if(!evId||!canvas.width)return;const fd=new URLSearchParams({action:'fwpe_save_edited_evidence',nonce:window.FWPE_FRONT_EDITOR.nonce,evidence_id:evId,image_data:canvas.toDataURL('image/jpeg',.92)});fetch(window.FWPE_FRONT_EDITOR.ajax,{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:fd}).then(r=>r.json()).then(j=>{if(!j.success){note.textContent=j.data||'No se pudo guardar.';return}note.textContent='Guardado correctamente.';setTimeout(()=>location.reload(),500)}).catch(()=>note.textContent='Error de conexión.')};
});
</script>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://focuswshop.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://focuswshop.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://focuswshop.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://focuswshop.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://focuswshop.com/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
