WISKEYS
Inventaire Pro
'; if(D.view!=="list")h+=''; else h+=''+D.idx.length+' inventaire(s)'; h+='
'; if(D.view==="edit"){var v=G(),n=TI(v);h+='
'+(v.prop||"Nouveau")+' — '+v.ref+' — '+n+' él.
'} h+='
'; // ══ LIST ══ if(D.view==="list"){ h+='

Inventaires

Inventaires de référence — prise en gestion

'; h+=''; if(D.idx.length===0)h+='
📦

Aucun inventaire

'; else [].concat(D.idx).sort(function(a,b){return new Date(b.u)-new Date(a.u)}).forEach(function(e){ var d=new Date(e.date).toLocaleDateString("fr-FR"); h+='
'+(e.prop||"Sans nom")+'
'+(e.ref||"")+'
'+(e.owner?e.owner+" • ":"")+d+'
'+(e.ic||0)+' éléments
' }); h+='
'; } // ══ EDIT ══ else if(D.view==="edit"){ var v=G(),ri=v.ar; if(!v.acc)v.acc={wifi_nom:"",wifi_mdp:"",boite_cles:"",digicode:"",bip:"",alarme:"",parking:"",cles:"",autre:""}; if(!v.cpt)v.cpt={eau:"",elec:"",gaz:""}; if(!v.rc)v.rc=v.rooms.map(function(){return mkRoom()}); while(v.rc.length'; if(D.search.length>=2){var res=gSearch(D.search); if(res.length>0){h+='
';res.forEach(function(r){h+='
'+r.nm+''+r.rm+'
'});h+='
'} else h+='
Aucun résultat
'} h+='

📋 Infos logement

'+(D.sec.cfg?"▲":"▼")+'
'; if(D.sec.cfg){h+='
'} h+='

🔑 Accès & Connectivité

'+(D.sec.acc?"▲":"▼")+'
'; if(D.sec.acc){h+='
'; [["wifi_nom","📶 WiFi (nom)","Nom réseau"],["wifi_mdp","📶 WiFi (mdp)","Mot de passe"],["boite_cles","🔑 Boîte à clés","Code"],["digicode","🔢 Digicode","Code"],["bip","📡 Bip portail","Oui/Non"],["alarme","🚨 Alarme","Code"],["parking","🅿️ Parking","Emplacement"],["cles","🔑 Clés remises","Nb et type (ex: 2 clés porte + 1 bip)"],["autre","📝 Autre","Infos"]].forEach(function(f){h+='
'});h+='
'} h+='

📊 Compteurs

'+(D.sec.cpt?"▲":"▼")+'
'; if(D.sec.cpt){h+='
'} h+='
';v.rooms.forEach(function(rm,i){var n=v.items[i].length;var ev=v.items[i].filter(function(it){return it.co!==null}).length;var pOk=n>0&&ev===n;var pPart=n>0&&ev>0&&ev'+rm+(n>0?' '+(pOk?"✓":ev+"/"+n)+'':'')+''});h+='
'; if(ri>0)h+=''; h+='

'+v.rooms[ri]+'

'; if(ri▶'; h+='
'; if(v.items[ri].length>1)h+=''; h+=''; if(v.rooms.length>1)h+=''; h+='
'; h+='
'; if(D.showS&&sgs.length>0){ h+='
'; sgs.slice(0,15).forEach(function(s){ var ck=!!D.multiSel[s]; h+='
'+s+'
' }); if(selCount>0)h+='
✅ Ajouter '+selCount+' élément'+(selCount>1?"s":"")+'
'; h+='
'; } if(D.showS)h+='
'; h+='
Aucun élément — utilisez le champ ci-dessus
'; h+='
'; h+='
'; h+='0?' onclick="mvIt('+ri+','+ii+',-1)"':' style="opacity:.2"')+'>▲'; h+='▼'; h+='
'; h+=''+it.nm+''; h+='
'+it.qty+'
'; h+='
'; h+='
';CO.forEach(function(c,ci){var on=it.co===ci;h+=''});h+='
'; if(!showDet)h+=''; if(showDet){h+='
'} h+='
';phs.forEach(function(p,pi){h+='
'}); if(phs.length📷
'; h+='
🏠 État de la pièce (murs, sol, plafond)
'; [["murs","Murs"],["sol","Sol"],["plafond","Plafond"],["fenetres","Fenêtres"],["prises","Prises"]].forEach(function(f){h+='
'}); h+='
📷 Photos pièce ('+(rc.rph.length)+'/'+MAX_PH_ROOM+')
'; rc.rph.forEach(function(p,pi){h+='
'}); if(rc.rph.length📷
'; h+='

Signatures

Validation de l\'inventaire — signez ci-dessous

Propriétaire — '+(v.owner||"non renseigné")+''; if(v.sigO)h+=''; h+='
'; h+='
WISKEYS — '+v.insp+''; if(v.sigI)h+=''; h+='
'; h+='
📦
'; h+='

'+(v.prop||"Inventaire")+'

'; h+='

'+(v.ref||"")+'

'; h+='

'+ds+(v.owner?" — "+v.owner:"")+'

'; h+='

'+tot+' éléments

'; if(valTot>0)h+='

💰 '+valTot.toLocaleString("fr-FR")+' €

'; if(v.revision)h+='

📅 Révision : '+new Date(v.revision).toLocaleDateString("fr-FR")+'

'; h+='
'; h+='
'; CO.forEach(function(c,ci){if(cc[ci]>0)h+=''+c.l+': '+cc[ci]+''}); if(nc>0)h+='Non évalué: '+nc+''; h+='
'; // Accès if(v.acc){var aa=[];if(v.acc.wifi_nom)aa.push("📶 "+v.acc.wifi_nom);if(v.acc.boite_cles)aa.push("🔑 "+v.acc.boite_cles);if(v.acc.digicode)aa.push("🔢 "+v.acc.digicode);if(v.acc.alarme)aa.push("🚨 "+v.acc.alarme);if(v.acc.cles)aa.push("🔑 Clés: "+v.acc.cles); if(aa.length>0)h+='

🔑 Accès

'+aa.join(" • ")+'
'} // Compteurs if(v.cpt&&(v.cpt.eau||v.cpt.elec||v.cpt.gaz)){var bits=[];if(v.cpt.eau)bits.push("💧 "+v.cpt.eau);if(v.cpt.elec)bits.push("⚡ "+v.cpt.elec);if(v.cpt.gaz)bits.push("🔥 "+v.cpt.gaz); h+='

📊 Compteurs

'+bits.join(" • ")+'
'} // Linen var lin=linenSummary(v); if(lin.length>0){h+='

🛏️ Linge

';lin.forEach(function(l){h+=''});var totL=lin.reduce(function(s,l){return s+l.qty},0);h+='
'+l.nm+''+l.room+''+l.qty+'
Total'+totL+'
'} // Rooms v.rooms.forEach(function(rm,ri){ if(v.items[ri].length===0)return; h+='

'+rm+' ('+v.items[ri].length+')

'; if(v.rc&&v.rc[ri]){var rc=v.rc[ri];var bits=[];if(rc.murs!=="—")bits.push("Murs: "+rc.murs);if(rc.sol!=="—")bits.push("Sol: "+rc.sol);if(rc.plafond!=="—")bits.push("Plafond: "+rc.plafond); if(bits.length>0)h+='
'+bits.join(" • ")+'
'; if(rc.rph&&rc.rph.length>0)h+='
📷 '+rc.rph.length+' photo(s)
'} v.items[ri].forEach(function(it){ var co=it.co!==null?CO[it.co]:null;var det=[];if(it.mq)det.push(it.mq);if(it.md)det.push(it.md);if(it.sn)det.push("N°"+it.sn);if(it.val)det.push(it.val+"€");if(it.taille)det.push(it.taille); h+='
'+it.nm+' × '+it.qty+''; if(det.length>0)h+='
'+det.join(" — ")+'
'; if(it.cm)h+='
💬 '+it.cm+'
'; if((it.ph||[]).length>0)h+='
📷 '+it.ph.length+'
'; h+='
';if(co)h+=''+co.l+'';h+='
'});h+='
'}); if(v.sigO||v.sigI){h+='
'; if(v.sigO)h+='
Propriétaire
'+(v.owner||"")+'
'; if(v.sigI)h+='
WISKEYS
'+v.insp+'
';h+='
'} if(v.notes)h+='
📝 '+v.notes+'
'; h+='
'; h+='

Ajouter une pièce

'; ROOM_PR.forEach(function(s){h+=''}); h+='

Nouveau inventaire

'; h+='

Choisissez un modèle pour pré-remplir les pièces et éléments. Tout est modifiable ensuite.

'; Object.keys(TPL).forEach(function(k){ var t=TPL[k],nR=t.rooms.length,nI=t.items.reduce(function(s,r){return s+r.length},0); var desc=k==="Vide"?"Inventaire vierge — ajoutez tout manuellement":nR+" pièces, "+nI+" éléments pré-remplis (état: Bon)"; var icon=k==="Vide"?"📝":k==="T1 / Studio"?"🏠":k==="T2"?"🏡":k==="T3"?"🏘️":"🏰"; h+=''; }); h+='
' } // ═══════ RENDER ═══════ function render(){ var a=document.getElementById("app"),h=""; h+=''; // Config h+=''; // Accès h+=''; // Compteurs h+=''; // Room tabs with reorder h+=''; // Room header + actions h+=''; // Add item — TOP position for easy access var sgs=D.showS?getSug(v.rooms[ri],D.sf):[]; var selCount=Object.keys(D.multiSel).filter(function(k){return D.multiSel[k]}).length; h+=''; // Items var its=v.items[ri]; if(its.length===0)h+=''; its.forEach(function(it,ii){ var phs=it.ph||[];var dk=ri+"-"+ii;var showDet=D.detOpen[dk]||it.det; var isNew=D.lastAdded===dk; h+=''; }); if(D.lastAdded)setTimeout(function(){D.lastAdded=null},1600); // Room condition AFTER items var rc=v.rc[ri];if(!rc.rph)rc.rph=[]; h+=''; // Notes h+=''; h+=''; h+=''; h+=''; h+=''; } // ══ SIGNATURES ══ else if(D.view==="sign"){ var v=G(); h+=''; h+=''; h+=''; } // ══ SUMMARY ══ else if(D.view==="summary"){ var v=G(),tot=TI(v),ds=new Date(v.date).toLocaleDateString("fr-FR",{day:"numeric",month:"long",year:"numeric"}); var cc=[0,0,0,0,0],nc=0,valTot=0; v.items.forEach(function(rm){rm.forEach(function(it){if(it.co!==null)cc[it.co]++;else nc++;if(it.val)valTot+=parseFloat(it.val)||0})}); h+=''; } h+=''; // Modal if(D.modal==="ar"){ h+=''} // Template modal if(D.modal==="tpl"){ h+=''} a.innerHTML=h; if(D.view==="sign"){var v=G();initSig("sO",v.sigO,"sigO");initSig("sI",v.sigI,"sigI")} if(D.view==="edit"&&D.showS){var ni=document.getElementById("ni");if(ni){ni.focus();ni.setSelectionRange(ni.value.length,ni.value.length)}} } loadAll();render(); if(WKI.editId){api('GET','/inventaires/'+WKI.editId).then(function(data){var lid='wp-'+WKI.editId;data._pid=WKI.editId;data.id=lid;D.inv[lid]=data;D.cid=lid;D.view='edit';D.sec={cfg:true,acc:false,cpt:false};render()}).catch(function(){toast("⚠️ Introuvable")})}