/g,">").replace(/"/g,""").replace(/'/g,"'");}function findProductById(id){return appState.products.find(product=>product.id.toString()===id.toString())||null;}document.addEventListener('DOMContentLoaded',()=>{appState.userId=getUserId();console.log('JS: userId atual:',appState.userId);let localHistory=JSON.parse(localStorage.getItem('reading_history')||'{}')[appState.userId]||[];console.log('JS: Histórico do localStorage:',localHistory);const historyGrid=document.getElementById('history-grid');const emptyMessage=document.getElementById('empty-message');if(localHistory.length>0){console.log('JS: Itens encontrados no localStorage, renderizando grid');emptyMessage.remove();localHistory.forEach(item=>{console.log('JS: Adicionando item ao grid:',item);const product=findProductById(item.id);const files=product&&product.digital_files?product.digital_files:[];const hasRarOrZip=files.some(file=>file.endsWith('.rar')||file.endsWith('.zip'));const detailUrl=hasRarOrZip?`detalhes3.php?id=${encodeURIComponent(item.id)}`:`detalhes.php?id=${encodeURIComponent(item.id)}&files=${encodeURIComponent(JSON.stringify(files))}`;const card=document.createElement('div');card.className='history-card bg-white rounded-lg p-3 sm:p-4 shadow-md border border-amber-500 cursor-pointer';card.setAttribute('role','button');card.setAttribute('aria-label',`Livro ${escapeHtml(item.title)}`);card.onclick=()=>{window.location.href=detailUrl;};card.innerHTML=`