File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/folders.js
preloadIcons("Folder20Regular","Warning20Regular","ChevronRight16Regular","ChevronDown16Regular"),function(){"use strict";var O=null,F="",D=null,f=document.getElementById("tree-root"),T=document.getElementById("tree-skeleton"),p=document.getElementById("grid-skeleton"),y=document.getElementById("photo-grid"),C=document.getElementById("breadcrumb"),g=document.getElementById("empty-state"),I=document.getElementById("photo-count-summary");function N(e,t){for(var n={name:t||"Root",id:null,photoCount:0,children:[],path:""},r=0;r<e.length;r++){var l=e[r],o=l.path;if(o.charAt(0)==="/"&&(o=o.substring(1)),o.charAt(o.length-1)==="/"&&(o=o.substring(0,o.length-1)),!o){n.id=l.id,n.photoCount+=l.photoCount;continue}for(var h=o.split("/"),a=n,u=0;u<h.length;u++){for(var m=h[u],s=null,d=0;d<a.children.length;d++)if(a.children[d].name===m){s=a.children[d];break}s||(s={name:m,id:null,photoCount:0,children:[],path:h.slice(0,u+1).join("/")},a.children.push(s)),a=s}a.id=l.id,a.photoCount+=l.photoCount}return V(n),k(n),n}function V(e){e.children.sort(function(n,r){return n.name.localeCompare(r.name)});for(var t=0;t<e.children.length;t++)V(e.children[t])}function k(e){for(var t=e.photoCount,n=0;n<e.children.length;n++)t+=k(e.children[n]);return e.totalCount=t,t}function x(e,t,n,r){var l=document.createDocumentFragment();S(e,t,l,r),n.appendChild(l)}function S(e,t,n,r){var l=document.createElement("div");l.className="tree-node";var o=document.createElement("div");o.className="tree-row",o.style.paddingLeft=8+t*16+"px";var h=e.children.length>0,a=document.createElement("span");a.className="tree-arrow"+(h?r?" expanded":"":" leaf"),a.innerHTML="",ensureIcon(a,"ChevronRight16Regular"),o.appendChild(a);var u=document.createElement("span");u.className="tree-icon",ensureIcon(u,"Folder20Regular"),o.appendChild(u);var m=document.createElement("span");m.className="tree-name",m.textContent=e.name,m.title=e.path||e.name,o.appendChild(m);var s=document.createElement("span");s.className="tree-count",s.textContent=(e.totalCount||0).toLocaleString(Od4Strings.resolveLocale()),o.appendChild(s),l.appendChild(o);var d=null;if(h){d=document.createElement("div"),d.className="tree-children"+(r?" open":"");for(var c=0;c<e.children.length;c++)S(e.children[c],t+1,d,!1);l.appendChild(d)}o.addEventListener("click",function(v){if(v.stopPropagation(),h&&v.target===a){var L=d.classList.contains("open");d.classList.toggle("open"),a.classList.toggle("expanded"),a.innerHTML="",ensureIcon(a,L?"ChevronRight16Regular":"ChevronDown16Regular");return}R(e,o),h&&d&&!d.classList.contains("open")&&(d.classList.add("open"),a.classList.add("expanded"),a.innerHTML="",ensureIcon(a,"ChevronDown16Regular"))}),n.appendChild(l)}function R(e,t){var n=f.querySelector(".tree-row.active");n&&n.classList.remove("active"),t.classList.add("active"),O=e.id,F=e.path||e.name,B(F||e.name),P(e.id)}function B(e){C.innerHTML="";var t=e?e.split("/"):[];t.length===0&&(t=["Root"]);for(var n=0;n<t.length;n++){if(n>0){var r=document.createElement("span");r.className="sep",r.textContent=Od4Strings.t("foldersPathSeparator"),C.appendChild(r)}var l=document.createElement("span");l.textContent=t[n],n===t.length-1&&(l.className="current"),C.appendChild(l)}}var i=[],w=new Map;function b(){w.clear();for(var e=0;e<i.length;e++){var t=i[e];if(t){var n=t.thumbnailId||t.driveItemId;n!=null&&w.set(n,e)}}}function E(e){return e?{id:e.thumbnailId||e.driveItemId,thumbnailId:Od4Shared.NumericUtils.toPositiveInt(e.thumbnailId),driveId:null,driveItemId:e.driveItemId||null,isVideo:e.isVideo||0,isFromICloud:e.isFromICloud||0,width:e.width||null,height:e.height||null,isFavorite:e.isFavorite||0,canEdit:e.canEdit!=null?e.canEdit:1,isCheckedOutByAnotherUser:e.isCheckedOutByAnotherUser?1:0}:null}function U(e){return e?{id:e.thumbnailId||e.driveItemId,thumbnailId:Od4Shared.NumericUtils.toPositiveInt(e.thumbnailId),driveId:null,driveItemId:e.driveItemId||null,isVideo:e.isVideo||0,isFromICloud:e.isFromICloud||0,width:e.width||null,height:e.height||null,isFavorite:e.isFavorite||0,name:e.name||"",date:e.takenDateTime||"",canEdit:e.canEdit!=null?e.canEdit:1,isCheckedOutByAnotherUser:e.isCheckedOutByAnotherUser?1:0}:null}ViewLib.OneUpNeighbors.install(ViewLib.OneUpNeighbors.arrayResolver({getItems:function(){return i},indexOfId:function(e){return w.get(e)},makeItem:function(e,t){return t?U(e):E(e)}})),window.addEventListener("message",function(e){if(e.data){if(e.data.type==="favorite-changed"){for(var t=0;t<i.length;t++)if(i[t]&&i[t].driveItemId===e.data.driveItemId){i[t].isFavorite=e.data.isFavorite;break}}if(e.data.type==="photo-deleted"){for(var n=e.data.driveItemId,r=0;r<i.length;r++)if(i[r]&&(i[r].driveItemId===n||String(i[r].driveItemId)===String(n))){i.splice(r,1);break}}}});function P(e){if(!e){y.innerHTML="",g.style.display="flex",I.textContent="",p.style.display="none",i=[],b();return}g.style.display="none",y.innerHTML="",p.style.display="grid",I.textContent="",fetch("/api/thumbnails?folderIds="+encodeURIComponent(e)+"&limit=100",{_od4ApiName:"thumbnail.batch"}).then(function(t){return t.json()}).then(function(t){p.style.display="none";var n=t.items||[],r=t.total||n.length;if(n.length===0){g.style.display="flex",I.textContent="",i=[],b();return}i=n,b();var l=ViewLib.FormatCount.formatCount(r,"sourcesPhotoCount"),o=r>100?" (showing first 100)":"";I.textContent=l+o;for(var h=document.createDocumentFragment(),a=0;a<n.length;a++){var u=n[a],m=document.createElement("div");m.className="photo-cell";var s=document.createElement("img"),d=u.thumbnailId;d&&(s.dataset.od4ApiName="thumbnail.single",s.src=ViewLib.Thumbnail.buildThumbnailUrl(d)),s.alt=u.name||"",s.loading="lazy",s.decoding="async",m.appendChild(s),function(c,v){m.addEventListener("click",function(){var L=v>0&&i[v-1]?E(i[v-1]):null,A=v<i.length-1&&i[v+1]?E(i[v+1]):null;ViewLib.Messages.sendToShell({type:"photo-selected",photo:{id:c.thumbnailId||c.driveItemId,thumbnailId:Od4Shared.NumericUtils.toPositiveInt(c.thumbnailId),driveId:null,driveItemId:c.driveItemId||null,name:c.name||"",date:c.takenDateTime||"",isVideo:c.isVideo||0,isFromICloud:c.isFromICloud||0,width:c.width||null,height:c.height||null,isFavorite:c.isFavorite||0},prevItem:L,nextItem:A})})}(u,a),h.appendChild(m)}y.appendChild(h)}).catch(function(t){p.style.display="none",g.style.display="flex",console.error("[folders] Failed to load photos:",t)})}var M=Date.now();fetch("/api/folders").then(function(e){return e.json()}).then(function(e){D=e,T.style.display="none",p.style.display="none";var t=N(e.cloud||[],"OneDrive"),n=e.local&&e.local.length>0?N(e.local||[],e.localRootName||"Local"):null;if(x(t,0,f,!0),n&&x(n,0,f,!1),t.id){var r=f.querySelector(".tree-row");r&&R(t,r)}window.ViewLib&&ViewLib.Messages&&ViewLib.Messages.sendVpHarnessScenario("loadFoldersView",{ksId:6551,resultType:"success",duration:Date.now()-M})}).catch(function(e){T.style.display="none",p.style.display="none";var t=document.createElement("div");t.className="empty-view empty-view-fill";var n=document.createElement("div");n.className="icon",ensureIcon(n,"Warning20Regular","icon-lg");var r=document.createElement("div");r.className="empty-view-text";var l=document.createElement("p");l.className="empty-view-body",l.textContent=Od4Strings.t("foldersFailed"),r.appendChild(l),t.append(n,r),f.appendChild(t),console.error("[folders] Failed to load folder tree:",e),window.ViewLib&&ViewLib.Messages&&ViewLib.Messages.sendVpHarnessScenario("loadFoldersView",{ksId:6551,resultType:"unexpected-failure",resultCode:e&&e.name||"UnknownError",duration:Date.now()-M})}),document.addEventListener("keydown",function(e){(e.ctrlKey||e.metaKey)&&(e.key==="a"||e.key==="d")&&!(e.target instanceof Element&&e.target.closest("input,textarea"))&&e.preventDefault()}),ViewLib.Messages.sendViewReadyToShell("folders.html")}();