HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/albums.js
preloadIcons("Checkmark16Regular","Dismiss20Regular","Album20Regular","Delete20Regular","Share20Regular","Star24Regular","Star24Filled","Flag20Regular","Checkmark20Regular","Link20Regular","AlbumAdd20Regular"),function(){"use strict";var ri=6575,li=6832,g=function(){var e=window.ViewLib&&window.ViewLib.ECS,t=e&&e.getE2EOverride&&e.getE2EOverride("NucleusAlbums");return typeof t=="boolean"?t:!!(e&&e.isRampEnabled(ri)&&e.isRampEnabled(li))}(),oi=6584,di=!window.ViewLib||!window.ViewLib.ECS||ViewLib.ECS.isKillswitchSafe(oi);di||document.documentElement.classList.add("album-empty-cover-legacy");var $=ViewLib.Messages.beginViewLoaded();function si(){return!!(window.ViewLib&&ViewLib.ECS&&ViewLib.ECS.isKillswitchSafe(7165))}function oe(){return!!(window.ViewLib&&ViewLib.ECS&&ViewLib.ECS.isRampEnabled&&ViewLib.ECS.isRampEnabled(6220))}ViewLib.Messages.onMessageType("page-visibility",function(e){e.visible&&($.beginRevisit(),$.revisitCached())});var yt=0,gt=0,be=ViewLib.Messages.beginDwellTracker({component:"Albums",apiName:"albumsview",ksId:6069,getExtraData:function(){return{albums:yt,sharedAlbums:gt,subScenario:"albumsview"}}}),N=document.getElementById("loading"),je=document.getElementById("signin-prompt"),ee=document.getElementById("signinBtn"),R=document.getElementById("album-grid"),L=document.getElementById("gridContainer"),Ee=document.getElementById("toolbarTitle");if(g){let e=function(){var t=document.getElementById("pageHeader");t&&(t.style.display="")};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e()}var pe=document.getElementById("createModal"),ui=document.getElementById("deleteDialog"),ci=document.getElementById("removeFromAlbumDialog"),mi=document.getElementById("reportConcernDialog"),fi=document.getElementById("reportDialogBanner"),vi=document.getElementById("reportCategories"),hi=document.getElementById("reportSubmitBtn"),bi=document.getElementById("reportDoneBtn"),pi=document.getElementById("reportFormState"),yi=document.getElementById("reportSentState"),gi=document.getElementById("reportFormActions"),wi=document.getElementById("reportSentActions"),Ii=document.getElementById("reportErrorMsg"),_i=document.getElementById("reportSpinner"),De=document.getElementById("albumNameInput"),Si=document.getElementById("createCancelBtn"),We=document.getElementById("createConfirmBtn"),V=document.getElementById("album-detail"),te=document.getElementById("detailHero"),A=document.getElementById("detailHeroBg")||te,Je=document.getElementById("detailBackBtn"),U=document.getElementById("detailNameEdit"),Te=document.getElementById("detailNameDisplay"),Q=document.getElementById("detailLoading"),W=document.getElementById("detailEmpty"),de=document.getElementById("detailDeleted"),se=document.getElementById("detailError"),ke=document.getElementById("detail-gallery-wrapper"),q=document.getElementById("detail-scroll-container"),J=document.getElementById("detail-scroll-content"),ye=document.getElementById("detail-canvas"),Ke=null,Ai=document.getElementById("detail-overlay-canvas"),B=document.getElementById("detail-hover-delete-btn"),n=null,ie=null,ge=null;function Ci(){return!ge&&q&&(ge=ViewLib.ImmersiveScrollbarProxy.create({scrollContainer:q,observeEls:[J]})),ge}function wt(e){if(!(!n||!e||e.length===0)){var t=e[0],i=O.itemAt(t);t<0||!i||(n.selectedItems.clear(),n.selectedItems.add(t),n.needsRender=!0,St=i,Ue())}}B&&B.addEventListener("click",function(e){if(e.stopPropagation(),!!n){var t=n._deleteBtnIdx>=0?n._deleteBtnIdx:n.hoveredIndex;wt([t])}});function It(e,t,i){if(n&&!(i<0||i>=n.items.length)&&n.items[i]){St=O.itemAt(i),n._selectForContextMenu(i);for(var a=o?o.album_id:null,s=!!(o&&o._isShared),d=n.selectedItems.size>0&&n.selectedItems.has(i)?Array.from(n.selectedItems).sort(function(r,h){return r-h}):[i],u=[],f=0;f<d.length;f++){var l=O.itemAt(d[f]);l&&u.push({id:l.thumbnail_id||l.thumbnailId||l.driveItemId,driveId:ViewLib.Ids.driveIdOf(l),driveItemId:l.driveItemId||null,name:l.name||"",isVideo:l.isVideo||0,isFavorite:l.isFavorite||0,isShared:l.isShared||0,isLocalOnly:l.isLocalOnly||0,fileSystemId:l.fileSystemId||null,placeholderState:l.placeholderState!=null?l.placeholderState:null,libraryTypeId:ViewLib.LibraryTypes.Albums,albumId:a,isSharedAlbum:s})}u.length&&Li.show(e,t,u)}}ye&&ye.addEventListener("contextmenu",function(e){if(e.preventDefault(),!!n){var t=n.hitTest(e.clientX,e.clientY);t<0||It(e.clientX,e.clientY,t)}});var E=[],H=[],we=null,Ie="date-created",k=null,Ye=null,ue=null,_t=2,Qe=200,Oe="square",Xe="compact",Li=initAlbumCtxMenu({getGallery:function(){return n},isActive:function(){return!!o},removeFromAlbum:function(){Ue()},setAsAlbumCover:function(e){ut(e)},reportConcern:function(e){hn(e)}}),St=null,o=null,Ve=!1,_=[],xe=new Map;function G(){if(!g){xe.clear();for(var e=0;e<_.length;e++){var t=_[e];if(t){var i=t.thumbnail_id||t.driveItemId;i!=null&&xe.set(i,e)}}}}var O=initAlbumDetailStore({getGallery:function(){return n},getDetailPhotos:function(){return _},isRampOn:function(){return g},getLegacyIdMap:function(){return xe}}),Ei=window.OD4AlbumsNeighborItems.makeItem,Di=window.OD4AlbumsNeighborItems.makeFullItem,Ti=ViewLib.OneUpNeighbors.arrayResolver({getItems:function(){return _},indexOfId:function(e){return xe.get(e)},makeItem:function(e,t){return t?Di(e):Ei(e)}});function ki(){return g&&n&&n._store?n._store:Ti}function Oi(e){e&&(e.albumId=o&&o.album_id||null,e.isSharedAlbum=!!(o&&o._isShared),e.libraryTypeId=ViewLib.LibraryTypes.Albums)}ViewLib.OneUpNeighbors.install(ki,{decorate:Oi}),window.addEventListener("message",function(e){if(e.data){if(e.data.type==="set-as-album-cover"){o&&o.album_id===e.data.albumId&&e.data.driveItemId&&ut({driveItemId:e.data.driveItemId});return}if(e.data.type==="remove-from-album"){var t=e.data.albumId,i=e.data.driveItemId,a=o&&o.album_id===t?o:E.find(function(r){return r.album_id===t});if(!a||!a.driveId){window.parent.postMessage({type:"remove-from-album-reply",driveItemId:i,success:!1},"*");return}fetch(ce(a,"/oneDrive.manageItems"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:[{id:i,"@oneDrive.removed":"deleted"}]})}).then(function(r){var h=r.ok||r.status===207;if(h){g&&n&&n._store?(n._applyRemove({id:i}),O.postMutationRender()):(_=_.filter(function(c){return c.driveItemId!==i}),G()),ae();var p=O.count();p===0?ve():o&&(o.cover_drive_item_id===i||o.cover_image_id===i)&&rt(),o&&!g&&(o.child_count=p)}window.parent.postMessage({type:"remove-from-album-reply",driveItemId:i,success:h},"*")}).catch(function(){window.parent.postMessage({type:"remove-from-album-reply",driveItemId:i,success:!1},"*")});return}if(e.data.type==="favorite-changed"&&e.data.driveItemId){var s=O.itemAt(O.indexOfId(e.data.driveItemId));s&&(s.isFavorite=e.data.isFavorite,g&&n&&(n.needsRender=!0))}if(e.data.type==="photo-deleted"){var d=e.data.driveItemId;if(g&&n&&n._store)n._applyRemove({id:d})&&O.postMutationRender();else for(var u=0;u<_.length;u++)if(_[u]&&(_[u].driveItemId===d||String(_[u].driveItemId)===String(d))){_.splice(u,1),G(),fe();break}}if(e.data.type==="nucleus-freshness-ready"){if(!oe())return;var f=e.data.trackingId,l={driveItemId:e.data.driveItemId||null,fsid:e.data.fsid||null,listId:e.data.listId||null,contentTag:e.data.contentTag||null,requiresFreshTexture:e.data.requiresFreshTexture===!0,anchorTimeMs:typeof e.data.anchorTimeMs=="number"?e.data.anchorTimeMs:0,imageModTimeMs:typeof e.data.imageModTimeMs=="number"?e.data.imageModTimeMs:0};typeof f=="number"&&(l.driveItemId||l.fsid)&&n&&n.notifyOnNextPaint&&n.notifyOnNextPaint(l,function(){var r=Date.now();window.parent.postMessage({type:"nucleus-freshness-thumbnail-loaded",trackingId:f,observedAtMs:r,cacheHit:!1},"*"),window.parent.postMessage({type:"nucleus-freshness-item-rendered",trackingId:f,observedAtMs:r,view:"albums"},"*")})}e.data.type==="album-l2-action"&&o&&(e.data.action==="share"?lt(o):e.data.action==="delete"?Zt(o.album_id):e.data.action==="add-photos"&&an(o))}});var Ze=window.OD4AlbumsImageCache,$e=Ze.getCachedImg,Me=Ze.putCachedImg,_n=Ze.fetchAuthImg,Re=window.OD4AlbumsPhotoRendering,Vi=Re.snapToThumbRamp,At=Re.applyHeroCrop,ne=Re.escapeHtml,Sn=Re.buildPhotoObj;Od4Strings.applyToDOM(je),ee.addEventListener("click",function(){ee.textContent=Od4Strings.t("signingIn"),ee.disabled=!0,ViewLib.Auth.signIn("viewCTA.albums").then(function(e){if(!e){ee.textContent=Od4Strings.t("signIn"),ee.disabled=!1;return}location.reload()}).catch(function(){ViewLib.Auth.postSignInEvent("completeFailure","viewCTA.albums","cancelled"),ee.textContent=Od4Strings.t("signIn"),ee.disabled=!1})});var xi=window.OD4AlbumsSkeletonLoading.createShowSkeletons({gridContainer:L,loadingEl:N,albumGrid:R}),S=window.OD4AlbumsCloudData,Ct=S.getCloudToken,K=S.ensureCloudAuth,An=S.doCloudFetch,P=S.cloudFetch,Lt=S.cloudFetchAbsolute,Mi=S.cloudFetchFromDrive,ce=S.nucleusAlbumUrl,et=S.fetchAlbumPermissions,Ri=S.fetchAlbumPermissionsDirect,Cn=S.parsePermissions,Et=S.parseAlbumPermissionsJson,Dt=S.fetchSharedAlbums;async function Bi(){if(!window.ViewLib||!window.ViewLib.SQL)return{owned:[],shared:[]};var e=window.OD4AlbumsGridMutations,t=await Promise.all([window.ViewLib.SQL.named("albums_list_v2",e.albumTypeOptions(!1)),window.ViewLib.SQL.named("albums_list_v2",e.albumTypeOptions(!0))]);return{owned:t[0].map(e.buildRecordFromRow),shared:t[1].map(e.buildRecordFromRow)}}async function Tt(){try{if(!ViewLib.AuthState.isAuthenticated()){N.style.display="none",R.style.display="none",je.style.display="flex",ViewLib.Auth.postSignInEvent("promptShown","viewCTA.albums");return}if(xi(),g){try{var e=await Bi();if(E=e.owned,H=e.shared,N.style.display="none",z(),R.style.display="block",$.firstLoad(),E.length){var t=E.some(function(c){return!!c.sharedWithPermissions});if(t){var i=!1;E.forEach(function(c){var m=Et(c.sharedWithPermissions);(m.people.length||m.showLink)&&(i=!0),c.shared_with=m.people,c._sharedLink=m.showLink}),i&&z()}else{var a=null;try{a=await Ct()}catch{}a&&Promise.all(E.map(function(c){return Ri(c.driveId,c.album_id,a).catch(function(){return{people:[],showLink:!1}})})).then(function(c){var m=!1;E.forEach(function(v,b){(c[b].people.length||c[b].showLink)&&(m=!0),v.shared_with=c[b].people,v._sharedLink=c[b].showLink}),m&&z()})}}}catch(c){console.error("Failed to load albums:",c),$.fail(c&&c.name||"UnknownError"),L.innerHTML="";try{await ViewLib.Auth.getToken(),N.style.display="flex",N.textContent=Od4Strings.t("albumsFailed")}catch{N.style.display="none",R.style.display="none",je.style.display="flex"}}return}try{await K();var s=await Promise.all([P("albums?expand=thumbnails&prefer=getStaticThumbnailUrls"),Dt()]),d=await s[0].json(),u=d.value||[];E=u.map(function(c){var m=c.thumbnails&&c.thumbnails.length>0&&c.thumbnails[0].large?c.thumbnails[0].large.url:null,v=c.mediaAlbum&&c.mediaAlbum.coverImageId||c.thumbnails&&c.thumbnails.length>0&&c.thumbnails[0].large&&c.thumbnails[0].large.sourceItemId||null;return!m&&v&&(m="https://my.microsoftpersonalcontent.com/_api/v2.1/drives/"+S.cloudDriveId+"/items/"+v+"/thumbnails/0/large/content"),{album_id:c.id,name:c.name||"Untitled",child_count:c.folder&&c.folder.childCount||c.bundle&&c.bundle.childCount||0,created_datetime:c.createdDateTime||"",last_modified_datetime:c.lastModifiedDateTime||"",cover_thumbnail_url:m,cover_image_id:v,local_cover_thumbnail_id:null,_hasShared:!!c.shared}});var f=await Promise.all(E.map(function(c){return c._hasShared?et(c.album_id):Promise.resolve({people:[],showLink:!1})}));E.forEach(function(c,m){c.shared_with=f[m].people,c._sharedLink=f[m].showLink}),H=s[1],N.style.display="none",z(),R.style.display="block",$.firstLoad()}catch(c){console.warn("Failed to load albums (cloud), retrying in 2s:",c.message),await new Promise(function(m){setTimeout(m,2e3)});try{await K();var l=await Promise.all([P("albums?expand=thumbnails&prefer=getStaticThumbnailUrls"),Dt()]),r=await l[0].json(),h=r.value||[];E=h.map(function(m){var v=m.thumbnails&&m.thumbnails.length>0&&m.thumbnails[0].large?m.thumbnails[0].large.url:null,b=m.mediaAlbum&&m.mediaAlbum.coverImageId||m.thumbnails&&m.thumbnails.length>0&&m.thumbnails[0].large&&m.thumbnails[0].large.sourceItemId||null;return!v&&b&&(v="https://my.microsoftpersonalcontent.com/_api/v2.1/drives/"+S.cloudDriveId+"/items/"+b+"/thumbnails/0/large/content"),{album_id:m.id,name:m.name||"Untitled",child_count:m.folder&&m.folder.childCount||m.bundle&&m.bundle.childCount||0,created_datetime:m.createdDateTime||"",last_modified_datetime:m.lastModifiedDateTime||"",cover_thumbnail_url:v,cover_image_id:b,local_cover_thumbnail_id:null,_hasShared:!!m.shared}});var p=await Promise.all(E.map(function(m){return m._hasShared?et(m.album_id):Promise.resolve({people:[],showLink:!1})}));E.forEach(function(m,v){m.shared_with=p[v].people,m._sharedLink=p[v].showLink}),H=l[1],N.style.display="none",z(),R.style.display="block",$.firstLoad()}catch(m){console.error("Failed to load albums (cloud) after retry:",m),$.fail(m&&m.name||"UnknownError"),document.body.style.overflowY="",L.innerHTML="",N.style.display="flex",N.textContent=Od4Strings.t("albumsFailed")}}}finally{ft=!1,T&&T.drainPostInitQueue()}}function kt(e){var t=Pt.buildCoverHtml(e,{isRampOn:g,escapeHtml:ne});return t+'<div class="card-gradient"></div><div class="card-overlay"><div class="album-name">'+ne(e.name||"Untitled")+'</div><div class="album-bottom-row"><div class="album-meta">'+Ot(e)+"</div></div></div>"}function Ot(e){var t="";e.created_datetime&&(t=Od4Shared.DateFormat.formatInLocalTimezone(e.created_datetime,{year:"numeric",month:"short"},Od4Strings.resolveLocale()));var i;if(e._isShared)if(e.shared_by){var a=ViewLib.Persona.getInitials(e.shared_by),s=ViewLib.Persona.getColorIndex(e.shared_by),d=Od4Strings.t("albumsSharedBy",[e.shared_by]);i='<span class="shared-by-row"><span class="persona-coin shared-by-coin" data-ci="'+s+'">'+ne(a)+'</span><span class="shared-by-label">'+ne(d)+"</span></span>";var u=e.child_count||0;i=ViewLib.FormatCount.formatCount(u,"sourcesItemCount")+" \xB7 "+i}else{var f=e.child_count||0;i=ViewLib.FormatCount.formatCount(f,"sourcesItemCount"),t&&(i+=" \xB7 "+t)}else{var l=e.child_count||0;if(i=ViewLib.FormatCount.formatCount(l,"sourcesItemCount"),t&&(i+=" \xB7 "+t),e.shared_with&&e.shared_with.length>0||e._sharedLink){for(var r=e.shared_with||[],h="",p=0;p<Math.min(r.length,3);p++){var c=r[p],m=ViewLib.Persona.getInitials(c),v=ViewLib.Persona.getColorIndex(c);h+='<span class="persona-coin shared-by-coin" data-ci="'+v+'" title="'+ne(c)+'">'+ne(m)+"</span>"}e._sharedLink&&(h+='<span class="shared-link-icon"></span>'),i='<span class="shared-meta-row"><span class="shared-coin-group">'+h+"</span><span>"+i+"</span></span>"}}return i}function Fi(e,t){var i=t.name||"Untitled",a=e.querySelector(".album-name");a&&(a.textContent=i);var s=e.querySelector(".album-card-link");s&&s.setAttribute("aria-label",i);var d=e.querySelector(".album-meta");d&&(d.innerHTML=Ot(t));var u=e.querySelector(".shared-link-icon");u&&ensureIcon(u,"Link20Regular")}function tt(e,t,i){var a=document.createElement("div"),s=!!(e.cover_thumbnail_url||e.local_cover_thumbnail_id&&(g||e.cover_drive_item_id)||g&&e._isShared&&e.cover_drive_item_id&&e.driveId||!g&&!e._isShared&&e.cover_drive_item_id);a.className="album-card "+(g?"album-card-enter":"album-card-legacy-enter")+(s?"":" album-card-empty")+(t?" "+t:""),g&&a.addEventListener("animationend",function(h){h.animationName==="cardEnter"&&a.classList.remove("album-card-enter")},{once:!0}),i&&(a.style.animationDelay=i),a.dataset.albumId=e.album_id,e.local_cover_thumbnail_id&&(a.dataset.coverThumbId=e.local_cover_thumbnail_id),e._isShared&&e.cover_drive_item_id&&e.driveId&&(a.dataset.coverFallbackUrl="http://photosapi.od4/SharePoint/_api/v2.1/drives/"+e.driveId+"/items/"+e.cover_drive_item_id+"/thumbnails/0/c400x400/content?prefer=noredirect%2Cclosestavailablesize"),a.innerHTML=kt(e);var d=a.querySelector(".shared-link-icon");d&&ensureIcon(d,"Link20Regular");var u=document.createElement("button");if(u.type="button",u.className="album-card-link",u.tabIndex=-1,u.setAttribute("role","menuitem"),u.setAttribute("aria-label",e.name||"Untitled"),a.insertBefore(u,a.firstChild),a.addEventListener("click",function(){Ne(e)}),!e._isShared){var f=document.createElement("button");f.type="button",f.className="album-action-btn album-delete-btn",f.title=Od4Strings.t("albumsDeleteBtn"),f.tabIndex=-1,ensureIcon(f,"Delete20Regular"),f.addEventListener("click",function(h){h.stopPropagation(),Zt(e.album_id)});var l=document.createElement("button");l.type="button",l.className="album-action-btn",l.dataset.action="share",l.title=Od4Strings.t("menuShare"),l.tabIndex=-1,ensureIcon(l,"Share20Regular"),Gt(l,e),l.addEventListener("click",function(h){h.stopPropagation(),lt(e)});var r=document.createElement("div");r.className="album-actions-container",r.appendChild(f),r.appendChild(l),a.querySelector(".album-bottom-row").appendChild(r)}return a}function Pi(e){var t=e.slice();return Ie==="name-asc"?t.sort(function(i,a){return(i.name||"").localeCompare(a.name||"")}):Ie==="last-modified"?t.sort(function(i,a){return(i.last_modified_datetime||"")>(a.last_modified_datetime||"")?-1:1}):t.sort(function(i,a){return(i.created_datetime||"")>(a.created_datetime||"")?-1:1}),t}function Ni(e){if(Ye===e&&ue){ue(!0);return}ue&&ue(!1),k||(k=document.createElement("div"),k.className="sort-menu",k.setAttribute("role","menu"),k.setAttribute("aria-label",Od4Strings.t("sort")),document.body.appendChild(k)),k.innerHTML="";var t=[{key:"name-asc",label:Od4Strings.t("albumsSortName")},{key:"date-created",label:Od4Strings.t("albumsSortDateCreated")},{key:"last-modified",label:Od4Strings.t("albumsSortLastModified")}];function i(l){Ye=null,ue=null,k.classList.contains("open")&&(k.classList.remove("open"),k.removeEventListener("keydown",f),document.removeEventListener("click",a),document.removeEventListener("scroll",s,!0),e.setAttribute("aria-expanded","false"),l&&e.focus())}function a(){i(!1)}function s(){i(!1)}t.forEach(function(l){var r=Ie===l.key,h=document.createElement("button");h.className="sort-menu-item"+(r?" active":""),h.setAttribute("role","menuitemradio"),h.setAttribute("aria-checked",r?"true":"false");var p=document.createElement("span");p.className="sort-menu-check",ensureIcon(p,"Checkmark16Regular"),h.appendChild(p);var c=document.createElement("span");c.textContent=l.label,h.appendChild(c),h.addEventListener("click",function(m){m.stopPropagation(),Ie=l.key,i(!1),z()}),k.appendChild(h)});var d=e.getBoundingClientRect();k.style.top=d.bottom+4+"px",k.style.right=window.innerWidth-d.right+"px",k.style.left="auto",k.classList.add("open"),Ye=e,e.setAttribute("aria-expanded","true"),ue=i;var u=k.querySelector(".sort-menu-item.active")||k.querySelector(".sort-menu-item");u&&u.focus();function f(l){var r=Array.from(k.querySelectorAll(".sort-menu-item")),h=r.indexOf(document.activeElement);l.key==="Escape"||l.key==="Tab"?(l.preventDefault(),i(!0)):l.key==="ArrowDown"?(l.preventDefault(),h<r.length-1&&r[h+1].focus()):l.key==="ArrowUp"&&(l.preventDefault(),h>0&&r[h-1].focus())}k.addEventListener("keydown",f),document.addEventListener("click",a),document.addEventListener("scroll",s,{once:!0,capture:!0})}var Be=null;function it(e){var t=Array.from(L.querySelectorAll(".album-card[data-shared-overflow]"));if(t.length){t.forEach(function(d){d.classList.remove("album-card-hidden")});var i=t[0].offsetTop,a=t.some(function(d){return d.offsetTop!==i});e&&t.forEach(function(d){d.classList.toggle("album-card-hidden",d.offsetTop!==i)});var s=L.querySelector(".chrome-btn-text[data-expanded]");s&&(s.style.display=a?"":"none")}}function Vt(e){if(e)for(var t=e.querySelectorAll(".album-card-link"),i=0;i<t.length;i++)t[i].setAttribute("aria-posinset",String(i+1)),t[i].setAttribute("aria-setsize",String(t.length))}function Ui(e){return L.querySelector('.album-section-list[data-section="'+(e?"shared":"mine")+'"]')}function xt(e,t,i){if(t){var a=document.createElement("div");if(a.className="view-section-header",a.style.gridColumn="1/-1",i){var s=document.createElement("h2");s.className="view-section-header-title",s.textContent=Od4Strings.t(t==="shared"?"albumsSectionShared":"albumsSectionMine"),a.appendChild(s)}if(t==="mine"){var d=document.createElement("div");d.className="view-section-header-actions";var u=document.createElement("button");u.className="chrome-btn-icon-text",u.setAttribute("aria-haspopup","menu"),u.setAttribute("aria-expanded","false"),u.setAttribute("aria-label",Od4Strings.t("sort")),ensureDualIcon(u,"ArrowSort20Regular"),u.appendChild(Object.assign(document.createElement("span"),{textContent:Od4Strings.t("sort")})),u.addEventListener("click",function(p){p.stopPropagation(),Ni(u)}),d.appendChild(u),a.appendChild(d)}if(t==="shared"&&e.length>1&&(!window.ViewLib||!window.ViewLib.ECS||window.ViewLib.ECS.isKillswitchSafe(5904))){var f=document.createElement("button");f.className="chrome-btn-text",f.dataset.expanded="0",f.textContent=Od4Strings.t("albumsSeeAll"),f.addEventListener("click",function(p){p.stopPropagation();var c=f.dataset.expanded!=="1";if(f.dataset.expanded=c?"1":"0",f.textContent=c?Od4Strings.t("albumsSeeLess"):Od4Strings.t("albumsSeeAll"),it(!c),c&&g){var m=!1;Array.from(L.querySelectorAll(".album-card[data-shared-overflow][data-cover-thumb-id]")).forEach(function(b){var I=b.querySelector(".cover-placeholder");if(I){var w=document.createElement("img");w.className="cover",w.dataset.localThumbId=b.dataset.coverThumbId,b.dataset.coverFallbackUrl&&(w.dataset.fallbackUrl=b.dataset.coverFallbackUrl),w.alt="",I.parentNode.replaceChild(w,I),m=!0}}),m&&Hi(L);var v=!1;Array.from(L.querySelectorAll(".album-card[data-shared-overflow][data-cover-fallback-url]")).forEach(function(b){if(!b.dataset.coverThumbId){var I=b.querySelector(".cover-placeholder");if(I){var w=document.createElement("img");w.className="cover",w.dataset.proxyCover=b.dataset.coverFallbackUrl,w.alt="",I.parentNode.replaceChild(w,I),v=!0}}}),v&&Gi(L)}}),a.appendChild(f)}L.appendChild(a)}var l=t==="mine"?Pi(e):e,r=document.createElement("div");r.className="album-section-list",r.setAttribute("role","menu");var h=t==="shared"||!t&&l.length>0&&!!l[0]&&!!l[0]._isShared;r.setAttribute("aria-label",Od4Strings.t(h?"albumsSectionShared":"albumsSectionMine")),r.dataset.section=h?"shared":"mine",l.forEach(function(p,c){var m=tt(p,null,c*60+"ms");t==="shared"&&c>0&&(!window.ViewLib||!window.ViewLib.ECS||window.ViewLib.ECS.isKillswitchSafe(5904))&&(m.dataset.sharedOverflow="1"),r.appendChild(m)}),Vt(r),L.appendChild(r),t==="shared"&&(!window.ViewLib||!window.ViewLib.ECS||window.ViewLib.ECS.isKillswitchSafe(5904))&&requestAnimationFrame(function(){it(!0),Be&&Be.disconnect(),Be=new ResizeObserver(function(){var p=L.querySelector(".chrome-btn-text[data-expanded]"),c=!p||p.dataset.expanded!=="1";it(c)}),Be.observe(L)})}var _e=window.OD4AlbumsGridCoverLoading.init({gridContainer:L,nucleusSupportAlbums:g,albumsCloudData:S,getCachedImg:$e,putCachedImg:Me}),qi=_e.loadCloudCoverEl,Mt=_e.doLoadCloudCovers,Hi=_e.batchLoadThumbImgs,Gi=_e.loadProxyCovers,Rt=_e.doLoadLocalCovers;function me(e,t){if(e){var i=e.querySelector(".album-card-link");i&&(i.tabIndex=t?0:-1);for(var a=e.querySelectorAll(".album-action-btn"),s=0;s<a.length;s++)a[s].tabIndex=t?0:-1}}function zi(){var e=L.querySelectorAll(".album-card:not(.album-card-hidden)");e.length&&me(e[0],!0)}function ji(){var e=Array.from(L.querySelectorAll(".album-card:not(.album-card-hidden)"));if(e.length<2)return 1;try{var t=window.getComputedStyle?getComputedStyle(L):null,i=t&&t.gridTemplateColumns;if(i&&i!=="none"&&i.indexOf("repeat(")===-1){var a=i.trim().split(/\s+/).filter(Boolean);if(a.length)return a.length}}catch{}for(var s=1,d=e[0].offsetTop,u=0,f=0;f<e.length;f++){var l=e[f].offsetTop;l===d?u++:(u>s&&(s=u),d=l,u=1)}return u>s&&(s=u),s}L.addEventListener("focusin",function(e){var t=e.target.closest&&e.target.closest(".album-card");if(t){var i=t.querySelector(".album-card-link");if(!(i&&i.tabIndex===0)){var a=L.querySelector('.album-card .album-card-link[tabindex="0"]'),s=a&&a.closest(".album-card");s&&s!==t&&me(s,!1),me(t,!0)}}}),L.addEventListener("keydown",function(e){if(!(e.key!=="ArrowLeft"&&e.key!=="ArrowRight"&&e.key!=="ArrowUp"&&e.key!=="ArrowDown")){var t=Array.from(L.querySelectorAll(".album-card:not(.album-card-hidden)")),i=document.activeElement,a=i&&i.closest&&i.closest(".album-card"),s=a?t.indexOf(a):-1;if(!(s<0)){e.preventDefault();var d=ji(),u=document.documentElement.dir==="rtl",f=e.key;u&&(f==="ArrowLeft"?f="ArrowRight":f==="ArrowRight"&&(f="ArrowLeft"));var l=s;if(f==="ArrowRight"?l=s+1:f==="ArrowLeft"?l=s-1:f==="ArrowDown"?l=s+d:f==="ArrowUp"&&(l=s-d),!(l<0||l>=t.length)){me(t[s],!1),me(t[l],!0);var r=t[l].querySelector(".album-card-link");r&&r.focus()}}}});function z(){document.body.style.overflowY="";var e=document.getElementById("pageHeader");e&&(e.style.display="");var t=H.length>0,i=E.length>0,a=t&&i;yt=E.length+H.length,gt=H.length,be.reportCounts(),L.innerHTML="",t&&xt(H,a?"shared":null,a),i&&xt(E,"mine",a);var s=document.getElementById("albumsEmpty");document.body.classList.toggle("albums-empty",!t&&!i),!t&&!i?s&&(s.style.display="flex",ensureIcon(document.getElementById("albumsEmptyCta"),"AlbumAdd20Regular")):s&&(s.style.display="none"),Mt(),Rt(),zi(),Wi()}function nt(e){return e&&(E.find(function(t){return t&&t.album_id===e})||H.find(function(t){return t&&t.album_id===e}))||null}function Wi(){var e=we;if(e&&(we=null,!(o&&o.album_id===e))){var t=nt(e);t&&Ne(t)}}function Ln(){n&&(n.gap=Xe==="roomy"?20:2,Bt())}function Bt(){if(n){var e=Oe==="river"||Oe==="waterfall"?"river":"grid";n.layoutMode=e,n.setZoom(Qe||200),n.resize(),n.needsRender=!0,n.loadVisibleTextures(),n.updateVisibleDateRange()}}function Ji(){return buildAlbumDetailScrollProxy(q,J)}function Ki(e){n&&(n.destroy(),n=null);var t=g&&e&&e.album_id?e.album_id:void 0;if(n=new WebGLGallery({embedded:!g,manageShellMargin:!0,transparent:!0,albumId:t,nucleusSupportsAlbums:g?1:0,canvas:ye,overlayCanvas:Ai,scrollContainer:Ji(),scrollContent:J,marqueeRoot:J,layoutMode:"river",gap:2,cornerRadius:4,padding:0,paddingBottom:100,headerOffset:0,deleteBtn:o&&o._isShared?null:B,hoverSurfaceContainer:document.getElementById("detail-scroll-container")}),window.__detailGallery=n,n.onLayoutChange=Fe,n._broadcastItemMatchesFilters=function(){return!1},window.AlbumsWs&&g&&window.AlbumsWs.installDetailGalleryHooks(n,{getCurrentAlbumId:function(){return o&&o.album_id}}),window.ViewLib&&window.ViewLib.TileHoverMirror&&window.ViewLib.TileHoverMirror.setDeleteHandler(n,wt),n._showContextMenu=It,g&&n._enrichAndLoad){var i=n._enrichAndLoad.bind(n);n._enrichAndLoad=function(l,r,h){return i(l,r,h).then(function(p){if(!p)return p;var c=o&&o.album_id||null,m=!!(o&&o._isShared);return p.forEach(function(v){v&&(v.libraryTypeId=ViewLib.LibraryTypes.Albums,v.albumId=c,v.isSharedAlbum=m,v.thumbnailId!=null&&v.thumbnail_id==null&&(v.thumbnail_id=v.thumbnailId))}),p})}}n.postSelectionChanged=function(){if(dt=new Set(this.selectedItems),st(),window.ViewLib&&window.ViewLib.TileHoverMirror)try{window.ViewLib.TileHoverMirror.update(this)}catch{}this.needsRender=!0},n.openPhotoDetails=function(l){var r=this.items[l];if(r){var h=this._getItemRect(l),p=this.canvas.getBoundingClientRect(),c=h?{x:p.left+h.x,y:p.top+h.y-this.scrollY,w:h.w,h:h.h}:null,m=this,v=function(I){var w=m.items[I];return w?{id:w.thumbnailId||w.driveItemId,thumbnailId:Od4Shared.NumericUtils.toPositiveInt(w.thumbnailId),driveId:w.driveId||null,driveItemId:w.driveItemId||null,videoContentDriveItemId:w.videoContentDriveItemId||null,isVideo:w.isVideo||0,width:w.width||null,height:w.height||null,isFavorite:w.isFavorite||0,placeholderState:w.placeholderState!=null?w.placeholderState:null,fileSystemId:w.fileSystemId||null,localId:w.localId||null,originalItemUniqueId:w.originalItemUniqueId||null,siteId:w.siteId||null,listId:w.listId||null,listItemUniqueId:w.listItemUniqueId||null,name:w.name||"",date:w.takenDateTime||""}:null},b={id:r.thumbnailId||r.driveItemId,thumbnailId:Od4Shared.NumericUtils.toPositiveInt(r.thumbnailId),name:r.name||"",date:r.takenDateTime||"",driveId:r.driveId||null,driveItemId:r.driveItemId||null,videoContentDriveItemId:r.videoContentDriveItemId||null,isVideo:r.isVideo||0,width:r.width||null,height:r.height||null,isFavorite:r.isFavorite||0,isShared:r.isShared||0,placeholderState:r.placeholderState!=null?r.placeholderState:null,fileSystemId:r.fileSystemId||null,localId:r.localId||null,originalItemUniqueId:r.originalItemUniqueId||null,siteId:r.siteId||null,listId:r.listId||null,listItemUniqueId:r.listItemUniqueId||null,libraryTypeId:ViewLib.LibraryTypes.Albums,albumId:r.albumId||null,isSharedAlbum:!!r.isSharedAlbum};ViewLib.Messages.sendToShell({type:"photo-selected",photo:b,prevItem:l>0?v(l-1):null,nextItem:l<this.items.length-1?v(l+1):null,thumbRect:c,viewSource:"album",albumId:o?o.album_id:null})}};var a=n.updateFavButton.bind(n);n.updateFavButton=function(){a();var l=document.getElementById("fav-btn-wrap");if(l){if(o&&o._isShared){l.style.display="none";return}if(l.style.display!=="none"){var r=this.items[this.hoveredIndex],h=!!(r&&r.isFavorite);l.classList.toggle("is-favorited",h);var p=document.getElementById("fav-btn-tooltip");p&&(p.textContent=Od4Strings.t(h?"galleryRemoveFavoriteBtn":"albumsAddToFav")),l.style.left=parseFloat(l.style.left)-9+"px",l.style.top=parseFloat(l.style.top)-9+"px"}}};var s=n.updateDeleteButton.bind(n);n.updateDeleteButton=function(){s(),!(!B||B.style.display==="none")&&(B.style.left=parseFloat(B.style.left)+11+"px",B.style.top=parseFloat(B.style.top)-9+"px")},document.body.classList.toggle("albums-shared-detail",!!(o&&o._isShared));var d=document.getElementById("fav-btn-wrap");d&&(d.style.display=o&&o._isShared?"none":"");var u=0,f=0;ie&&ie.disconnect(),ie=new ResizeObserver(function(l){var r=l[0]&&l[0].contentRect.width;r!==f&&(f=r,clearTimeout(u),u=setTimeout(function(){n&&(n.resize(),n.layoutMode==="river"?n.calculateRiverLayout(0):n.calculateLayout(),n.needsRender=!0,n.loadVisibleTextures())},50))}),ke&&ie.observe(ke)}function Yi(){if(ie&&(ie.disconnect(),ie=null),n&&(n.destroy(),n=null),window.__detailGallery=null,window.ViewLib&&window.ViewLib.TileHoverSurface&&typeof window.ViewLib.TileHoverSurface.hide=="function")try{window.ViewLib.TileHoverSurface.hide()}catch(t){console.error("Failed to hide TileHoverSurface:",t)}var e=document.getElementById("fav-btn-wrap");e&&(e.style.display="none"),B&&(B.style.display="none")}function Qi(e){for(var t=o&&o.album_id||null,i=!!(o&&o._isShared),a=[],s=0;s<e.length;s++){var d=e[s];if(d){var u={id:d.thumbnail_id||d.driveItemId,driveItemId:d.driveItemId||"",driveId:ViewLib.Ids.driveIdOf(d)||"",thumbnailId:d.thumbnail_id||null,name:d.name||"",width:d.width||0,height:d.height||0,isVideo:d.isVideo||0,takenDateTime:d.takenDateTime||null,isFavorite:d.isFavorite||0,isShared:d.isShared||0,isLocalOnly:d.isLocalOnly||0,fileSystemId:d.fileSystemId||null,placeholderState:d.placeholderState!=null?d.placeholderState:null,originalItemUniqueId:d.originalItemUniqueId||null,siteId:d.siteId||null,listId:d.listId||null,listItemUniqueId:d.listItemUniqueId||null,libraryTypeId:ViewLib.LibraryTypes.Albums,albumId:t,isSharedAlbum:i};oe()&&(u.listId=d.listId||null),a.push(u)}}return a}function Fe(){ViewLib.DetailContentCap.apply(J)}function fe(){if(n){if(g){n.updateVisibleDateRange&&n.updateVisibleDateRange(),Fe();return}n.setItems(_.length===0?[]:Qi(_)),n.updateVisibleDateRange&&n.updateVisibleDateRange(),Fe()}}var at=!1;function Xi(){at||(at=!0,requestAnimationFrame(function(){at=!1,n&&n.updateVisibleDateRange&&n.updateVisibleDateRange()}))}q&&(q.addEventListener("scroll",Xi,{passive:!0}),Ke=window.ViewLib&&ViewLib.DetailBackDock?ViewLib.DetailBackDock.attachDock({scrollContainer:q,hero:te,controls:document.getElementById("detailControls"),backWrap:document.getElementById("detailBackWrap")}):null);function j(e){A&&(A.dataset.heroBlobUrl&&(URL.revokeObjectURL(A.dataset.heroBlobUrl),delete A.dataset.heroBlobUrl),A.style.backgroundImage=e||"")}function Se(e){if(A){var t=URL.createObjectURL(e);j("url("+t+")"),A.dataset.heroBlobUrl=t}}function Zi(e){if(!e||e.byteLength<12)return null;var t=new DataView(e);if(t.getUint32(0,!0)===0)return null;var i=8,a=t.getUint32(i,!0);return i+=4,i+a>e.byteLength?null:new Uint8Array(e,i,a)}function Ft(e,t){if(t===o){var i=Zi(e);i?(Se(new Blob([i])),A.style.opacity="1"):t.cover_drive_item_id?X(t):A&&(A.style.opacity="1")}}function X(e){if(A.style.backgroundPosition="",g&&e.cover_drive_item_id){var t=e.cover_drive_item_id,i=[256,400,960,1600,2560],a=Math.max(window.innerWidth,te.offsetHeight)*devicePixelRatio,s=i.find(function(v){return v>=a})||i[i.length-1],d=ViewLib.Ids.driveIdOf({driveId:e.driveId,driveItemId:t});j("url(http://photosapi.od4/SharePoint/_api/v2.1/drives/"+d+"/items/"+t+"/thumbnails/0/c"+s+"x"+s+"/content?prefer=noredirect%2Cclosestavailablesize)"),A.style.opacity="1";return}if(e.cover_image_id&&!e._isShared){for(var u=[256,400,960,1600,2560],f=Math.max(window.innerWidth,te.offsetHeight)*devicePixelRatio,l=u[u.length-1],r=0;r<u.length;r++)if(u[r]>=f){l=u[r];break}var h="c"+l+"x"+l,p="items/"+e.cover_image_id+"/thumbnails/0/"+h+"/content",c=P(p).then(function(v){return v.ok?v.blob():null}).catch(function(){return null}),m=P("items/"+e.cover_image_id+"?select=image").then(function(v){return v.ok?v.json():null}).catch(function(){return null});Promise.all([c,m]).then(function(v){if(e===o){var b=v[0],I=v[1];I&&At(A,I),b?Se(b):e.cover_thumbnail_url&&j("url("+e.cover_thumbnail_url+")"),A.style.opacity="1"}})}else e.cover_thumbnail_url?$e(e.cover_thumbnail_url).then(function(v){if(e===o){if(v){j("url("+v+")"),A.style.opacity="1";return}var b=e.cover_thumbnail_url.indexOf("tempauth")!==-1?{_od4ApiName:"thumbnail"}:{headers:{Authorization:"Bearer "+S.cloudToken},_od4ApiName:"thumbnail"};fetch(e.cover_thumbnail_url,b).then(function(I){if(I.ok)return I.blob();throw new Error(I.status)}).then(function(I){Me(e.cover_thumbnail_url,I),e===o&&(Se(I),A.style.opacity="1")}).catch(function(){e===o&&(j("url("+e.cover_thumbnail_url+")"),A.style.opacity="1")})}}):A.style.opacity="1"}var Pt=window.OD4AlbumsCoverReplacement.create({getDetailAlbum:function(){return o},firstDetailItemId:function(){return O.idAt(0)},replaceHeroBackground:j,getHeroBg:function(){return A},loadDetailHero:function(e){return X(e)},cloudFetch:P,getAlbumGridEl:function(){return R},getGridContainer:function(){return L},loadCloudCoverEl:function(e){return qi(e)},isRampOn:function(){return g}}),rt=Pt.pickReplacementCover;function ve(){if(W){W.style.display="";var e=!!(o&&o._isShared),t=document.getElementById("detailEmptyTitle"),i=document.getElementById("detailEmptyBody");t&&(t.textContent=Od4Strings.t(e?"albumsDetailEmptyShared":"albumsDetailEmpty"));var a=document.getElementById("detailEmptyImgDark"),s=document.getElementById("detailEmptyImgLight"),d=e?"shared_":"";a&&(a.src="/static/albums_l2_emptyState_"+d+"dark_512.png"),s&&(s.src="/static/albums_l2_emptyState_"+d+"light_512.png"),i&&(e?(i.textContent=Od4Strings.t("albumsDetailEmptySharedBody"),i.style.display=""):i.style.display="none")}V.classList.add("detail-empty-visible");var u=document.getElementById("detail-scroll-content");u&&(u.style.display="none"),j(""),A&&(A.style.opacity="0"),o&&o.child_count===0&&(o.cover_image_id=null,o.cover_thumbnail_url=null)}function $i(){ae(),Q.style.display="none",se.style.display="none",W&&(W.style.display="none"),V.classList.remove("detail-empty-visible"),V.classList.add("detail-deleted-visible"),de&&(de.style.display="")}function en(e){if(g&&n&&n._store)e.forEach(function(r){r!=null&&n._applyRemove({id:r})}),ae(),O.postMutationRender();else{if(n&&n.items){for(var t=new Map,i=0;i<n.items.length;i++){var a=n.items[i];a&&a.driveItemId&&t.set(a.driveItemId,a.isFavorite?1:0)}for(var s=0;s<_.length;s++){var d=_[s];d&&t.has(d.driveItemId)&&(d.isFavorite=t.get(d.driveItemId))}}_=_.filter(function(r){return!e.has(r.driveItemId)}),G(),ae(),fe()}if(n){n.hoveredIndex=-1,n._deleteBtnIdx=-1,n.updateFavButton(),n.updateDeleteButton();var u=document.getElementById("fav-btn-wrap");u&&(u.style.display="none"),B&&(B.style.display="none"),n.needsRender=!0}var f=O.count();if(f===0)ve();else{var l=o&&(o.cover_drive_item_id||o.cover_image_id);l&&e.has(l)&&rt()}o&&!g&&(o.child_count=f)}function tn(e){var t=document.getElementById("detailControls"),i=window.GalleryControls;_t=i?i.getZoomIndex():2,Qe=i?i.getRowHeight():200;var a=i?i.getLayout():"square";Oe=a==="river"?"river":"square",Xe=i?i.getDensity():"compact";var s=document.getElementById("od4DateRangeText");s&&(s.textContent="");var d=document.getElementById("detailDateDisplay");d&&!d.querySelector(".fluent-icon")&&ensureDualIcon(d,"Calendar20Regular"),Ki(e),t.style.display="flex"}async function En(e){try{var t=await fetch("/api/albums/"+e.album_id+"/materialize",{method:"POST",_od4ApiName:"album.materialize"}),i=await t.json();i.error||ViewLib.Messages.sendOpenAlbumCollectionToShell(i.collectionId,i.name)}catch(a){console.error("Failed to open album:",a)}}var Pe=window.OD4AlbumsDetailStatus.createRenderer({escapeHtml:ne,getShareAlbum:function(){return lt}}),Nt=window.OD4AlbumsShareDialog.init({getDetailAlbum:function(){return o},fetchAlbumPermissions:et,renderDetailAlbumStatus:Pe,getCloudToken:Ct,ensureCloudAuth:K,cloudFetch:P,getCloudDriveId:function(){return S.cloudDriveId},getCloudTokenValue:function(){return S.cloudToken}}),nn=Nt.closeShareDialog,lt=Nt.shareAlbum,Ut=1e3;async function an(e){if(!(!e||e._isShared)){var t=window.ViewLib&&window.ViewLib.ECS;if(!(t&&!t.isKillswitchSafe(6303))&&window.MiniGallery){var i=Od4Strings.t("addPhotosTitle"),a=Od4Strings.t("ctxAddToAlbum");await window.MiniGallery.open({title:i,actionLabel:a,filter:{requireDriveItemId:!0,driveId:window.__od4AccountCid},maxSelectionCount:Ut,onInvoke:function(s){!s||!s.length||rn(e,s)}})}}}function rn(e,t){ViewLib.Messages.sendToastToShell(Od4Strings.t("ataAddingTo",[e.name]),"progress",0);for(var i=g,a=i?Ut:40,s=[],d=0;d<t.length;d+=a)s.push(t.slice(d,d+a));var u=S.isNullDriveIdFixSafe(),f=u?null:"https://my.microsoftpersonalcontent.com/_api/v2.1/drives/"+S.cloudDriveId+"/albums/"+e.album_id+"/oneDrive.manageItems",l=ce(e,"/oneDrive.manageItems"),r=0,h=0,p=null;Promise.all(s.map(function(c){var m={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",Prefer:"returnCopiedItems"},_od4ApiName:"album.manageItems",body:JSON.stringify({value:c.map(function(b){return{id:b}})})},v=i?fetch(l,m):u?K().then(function(){return Lt(S.albumManageItemsCloudUrl(e,S.cloudDriveId),m)}):Lt(f,m);return v.then(function(b){return b.ok?b.json():(console.warn("[albums] manageItems batch returned HTTP "+b.status),h++,p||(p="http-"+b.status),null)}).then(function(b){if(b){var I=b&&Array.isArray(b.value)?b.value:[],w=I.filter(function(Y){return Y&&Y.id&&!Y.error});return r+=w.length,ln(e,w)}}).catch(function(b){console.warn("[albums] manageItems batch failed:",b),h++,p||(p=b&&b.name||"batch-failed")})})).then(function(){if(ViewLib.Messages.sendDismissProgressToShell(),r>0){var c=ViewLib.FormatCount.formatCount(r,"ataAdded",[e.name]);ViewLib.Messages.sendToastToShell(c,"success",3e3),h>0&&console.warn("[albums] add photos: "+h+" batch(es) failed; "+r+" item(s) added")}else ViewLib.Messages.sendToastToShell(Od4Strings.t("ataAddFailed"),"error",3e3),ViewLib.Messages.sendVpScenario("addAlbumPhotos",{ksId:6551,resultType:"unexpected-failure",resultCode:p||(h>0?"all-batches-failed":"zero-added")})}).catch(function(c){console.error("[albums] add photos failed:",c),ViewLib.Messages.sendDismissProgressToShell(),ViewLib.Messages.sendToastToShell(Od4Strings.t("ataAddFailed"),"error",3e3),ViewLib.Messages.sendVpScenario("addAlbumPhotos",{ksId:6551,resultType:"unexpected-failure",resultCode:c&&c.name||"UnknownError"})})}var qt=window.OD4AlbumsDetailPhotoSorting.detailPhotoByDateDesc;function Ht(){return{getDetailAlbum:function(){return o},getAlbumDetailEl:function(){return V},getDetailCount:function(){return O.count()},getDetailEmptyEl:function(){return W},getDetailControlsEl:function(){return document.getElementById("detailControls")},getDetailScrollContentEl:function(){return J},loadDetailHero:X}}function ln(e,t){if(!t||!t.length||!o||o.album_id!==e.album_id)return Promise.resolve();var i=function(){!o||o.album_id!==e.album_id||window.AlbumsWs&&AlbumsWs.undoEmptyState(Ht())};if(g){if(!n||!n._ingestDeltaSync)return Promise.resolve();for(var a=[],s=0;s<t.length;s++){var d=t[s];!d||!d.id||d.error||a.push({driveItemId:d.id,takenDateTime:d.takenDateTime||null})}return a.length===0?Promise.resolve():Promise.resolve(n._ingestDeltaSync(a,{membershipVerified:!0})).then(i)}for(var u=[],f=0;f<t.length;f++){var l=t[f];if(!(!l||!l.id||l.error)&&!(O.indexOfId(l.id)>=0)){var r=l.copiedItem||{},h=r.image||r.video||{},p=null,c=null,m=null,v=null,b=r.image&&Array.isArray(r.image.cropRegions)?r.image.cropRegions:null;if(b){for(var I=0;I<b.length;I++)if(b[I]&&b[I].aspectRatio==="1"){p=b[I].boundingBoxX!=null?Math.round(b[I].boundingBoxX):null,c=b[I].boundingBoxY!=null?Math.round(b[I].boundingBoxY):null,m=b[I].boundingBoxWidth!=null?Math.round(b[I].boundingBoxWidth):null,v=b[I].boundingBoxHeight!=null?Math.round(b[I].boundingBoxHeight):null;break}}var w={driveItemId:l.id,driveId:r.parentReference&&r.parentReference.driveId||null,name:r.name||"",takenDateTime:r.photo&&r.photo.takenDateTime||r.createdDateTime||"",thumbnail_id:null,_cloudThumbUrl:null,width:h.width||null,height:h.height||null,faceCropX:p,faceCropY:c,faceCropW:m,faceCropH:v,isVideo:!!r.video,isFavorite:0,isShared:0,isLocalOnly:0,fileSystemId:null,placeholderState:null};oe()&&(w.listId=r.listId||r.sharepointIds&&r.sharepointIds.listId||r.parentReference&&r.parentReference.sharepointIds&&r.parentReference.sharepointIds.listId||null),u.push(w)}}if(u.length===0)return Promise.resolve();var Y=u.map(function(F){return F.driveItemId}),Z=window.ViewLib&&window.ViewLib.SQL,ze=Z?Z.named("albums_thumb_resolve",{params:{resource_ids:JSON.stringify(Y)}}).then(function(F){var M={};F.forEach(function(x){M[x.driveItemId]=x.id}),u.forEach(function(x){M[x.driveItemId]&&(x.thumbnail_id=M[x.driveItemId])})}).catch(function(){}):Promise.resolve();return ze.then(function(){if(!(!o||o.album_id!==e.album_id)){u.sort(qt);for(var F=new Array(_.length+u.length),M=0,x=0,C=0;M<_.length&&x<u.length;)qt(_[M],u[x])<=0?F[C++]=_[M++]:F[C++]=u[x++];for(;M<_.length;)F[C++]=_[M++];for(;x<u.length;)F[C++]=u[x++];_=F,G(),fe(),i()}})}function ot(e){return e?{driveId:e.driveId||S.cloudDriveId,driveItemId:e.album_id}:null}function Gt(e,t,i){if(!(!e||!window.Od4ActionAvailability||!window.Od4ActionAvailability.actions.share)){var a=window.Od4ActionAvailability.actions.share(t?[ot(t)]:[],{isOffline:i??!!(ViewLib.Offline&&ViewLib.Offline.isOffline()),surface:"album-card",viewContext:"album"});e.disabled=!a.enabled,e.hidden=!a.enabled}}function on(e){for(var t=document.querySelectorAll('.album-card .album-action-btn[data-action="share"]'),i=0;i<t.length;i++){var a=t[i].closest(".album-card"),s=a&&nt(a.dataset.albumId);Gt(t[i],s,e)}}function zt(e){window.dispatchEvent(new CustomEvent("od4-album-share-item-change",{detail:{item:ot(e)}}))}async function Ne(e){var t=!!o,i=ViewLib.Messages.beginViewLoaded({l2:"AlbumL2",identifier:e.album_id});R.style.display="none",N.style.display="none";var a=document.getElementById("pageHeader");a&&(a.style.display="none"),window.parent.postMessage({type:"close-details-pane"},"*"),document.documentElement.classList.add("l2-immersive"),Ci().enable(),window.parent.postMessage({type:"set-topbar-visible",visible:!1},"*"),window.parent.postMessage({type:"_vp_l2_view",view:"AlbumL2",shared:!!e._isShared,shareItem:ot(e)},"*"),be.settle(),be.setApiName("albumview"),ViewLib.Messages.sendVpAction("activateAlbumTile",{ksId:6010}),o=e,_=[],G(),zt(e),se.style.display="none",V.classList.remove("detail-deleted-visible"),de&&(de.style.display="none");var s=e.child_count===0||!g&&e._isShared&&!e.cover_thumbnail_url;s?(Q.style.display="none",ve()):(V.classList.remove("detail-empty-visible"),W.style.display="none",Q.style.display="",window._announceLoading&&window._announceLoading(Q,Od4Strings.t("navLoading"),{dedupKey:"albums-detail-loading"})),te&&(te.style.display="");var d=document.getElementById("detail-scroll-content");d&&(d.style.display=s?"none":""),tn(e);var u=e.name||"Untitled";U.value=u,Te.textContent=u,U.tabIndex=e._isShared?-1:0,Pe(e),Jt(e),Pe(e),q&&(q.scrollTop=0),Ke&&Ke.reset();var f=document.getElementById("detailBackWrap");f&&f.classList.remove("is-compact","is-docked");var l=document.getElementById("detailControls");l&&l.classList.remove("is-floating","is-scrolled","is-back-docked"),j(""),A.style.opacity="0",document.body.style.overflow="hidden",V.classList.add("is-entering"),V.addEventListener("animationend",function(){V.classList.remove("is-entering")},{once:!0}),V.style.display="",setTimeout(function(){Je&&Je.focus()},0),V.classList.add("webgl-mode"),ke&&(ke.style.display=""),Bt(),n&&(n.scrollY=0,n.targetScrollY=0),q&&(q.scrollTop=0),Ee.textContent=u;var r="?album="+e.album_id;if(t?history.replaceState({albumId:e.album_id},"",r):(history.pushState({albumId:e.album_id},"",r),ViewLib.Messages.coverBackNavigation()),e.cover_thumbnail_url)$e(e.cover_thumbnail_url).then(function(y){if(y){j("url("+y+")"),A.style.opacity="1";return}fetch(e.cover_thumbnail_url,{headers:{Authorization:"Bearer "+S.cloudToken},_od4ApiName:"thumbnail"}).then(function(D){if(D.ok)return D.blob();throw new Error(D.status)}).then(function(D){Me(e.cover_thumbnail_url,D),Se(D),A.style.opacity="1"}).catch(function(){A.style.opacity="1"})});else if(e.local_cover_thumbnail_id)if(g)fetch("/api/thumbnails/od4batch",{method:"POST",headers:{"Content-Type":ViewLib.ECS.jsonRequestContentType()},body:JSON.stringify({ids:[e.local_cover_thumbnail_id]}),_od4ApiName:"thumbnail.batch"}).then(function(y){return y.arrayBuffer()}).then(function(y){Ft(y,e)}).catch(function(){e===o&&(e.cover_drive_item_id?X(e):A.style.opacity="1")});else if(e.cover_drive_item_id){var h=e.cover_drive_item_id,p=ViewLib.Ids.driveIdOf({driveItemId:h});j("url(http://photosapi.od4/SharePoint/_api/v2.1/drives/"+p+"/items/"+h+"/thumbnails/0/c400x400/content?prefer=noredirect%2Cclosestavailablesize)"),A.style.opacity="1"}else A.style.opacity="1";else g&&e.cover_drive_item_id?X(e):A.style.opacity="1";try{if(g){Q.style.display="none";try{n&&n._initPromise&&await n._initPromise}catch(y){if(si())throw y;console.warn("Album detail init failed:",y)}if(!o||o.album_id!==e.album_id)return;ye&&(ye.style.visibility="visible"),n&&n.updateVisibleDateRange&&n.updateVisibleDateRange(),Fe(),O.count()===0&&ve(),window.__detailEnriched=!0,i.firstLoad();return}else{var c=e.child_count||0,m=[];_=m,G(),Q.style.display="none";var v,b;if(e._isShared)await K(),v="https://my.microsoftpersonalcontent.com/_api/v2.1/drives/"+e._cobDriveId+"/albums/"+e.album_id+"/children?select=createdBy,createdDateTime,cTag,description,driveId,file,fileSystemInfo,id,image,lastModifiedDateTime,location,name,parentReference,photo,shared,sharepointIds,size,video,webUrl,accessViewpoint&top=100&filter=photo+ne+null&expand=tags&ump=1",b=function(y){return fetch(y,{headers:{Authorization:"Bearer "+S.cloudToken,Accept:"application/json"}})};else{var I="id%2Cname%2Cphoto%2CcreatedDateTime%2Cimage%2Cvideo";oe()&&(I+="%2CparentReference%2CsharepointIds"),v="albums/"+e.album_id+"/children?select="+I+"&filter=photo+ne+null&$top=100",b=P}for(var w=0,Y=!1;v;){var Z=await b(v);if(Z.status===401&&!Y){Y=!0,S.cloudToken=null,await new Promise(function(y){setTimeout(y,1e3)}),await K(!0);continue}if(Z.status===401||Z.status===403){Q.style.display="none",se.textContent=Z.status===403?Od4Strings.t("albumsSharedAccessError"):Od4Strings.t("albumsFailed"),se.style.display="",document.getElementById("detailControls").style.display="none";var ze=document.getElementById("detail-scroll-content");ze&&(ze.style.display="none");return}Y=!1;for(var F=await Z.json(),M=F.value||[],x=0;x<M.length;x++,w++){var C=M[x],ti=C.image||C.video||{},ii={driveItemId:C.id,driveId:C.parentReference&&C.parentReference.driveId||null,name:C.name||"",takenDateTime:C.photo&&C.photo.takenDateTime||C.createdDateTime||"",thumbnail_id:null,_cloudThumbUrl:e._isShared?"https://my.microsoftpersonalcontent.com/_api/v2.1/drives/"+e._cobDriveId+"/items/"+C.id+"/thumbnails/0/large/content":null,width:ti.width||null,height:ti.height||null,isVideo:!!C.video,isFavorite:C.isFavorite||0,isShared:e._isShared?1:C.isShared||0,isLocalOnly:C.isLocalOnly||0,fileSystemId:C.fileSystemId||null,placeholderState:C.placeholderState!=null?C.placeholderState:null};oe()&&(ii.listId=C.listId||C.sharepointIds&&C.sharepointIds.listId||C.parentReference&&C.parentReference.sharepointIds&&C.parentReference.sharepointIds.listId||null),m[w]=ii}for(var bt=[],Le=w-M.length;Le<w;Le++)m[Le]&&m[Le].driveItemId&&bt.push(m[Le].driveItemId);if(bt.length>0&&window.ViewLib&&window.ViewLib.SQL)try{var wn=await window.ViewLib.SQL.named("albums_thumb_resolve",{params:{resource_ids:JSON.stringify(bt)}}),pt={};wn.forEach(function(y){pt[y.driveItemId]=y.id}),m.forEach(function(y){y&&!y.thumbnail_id&&pt[y.driveItemId]&&(y.thumbnail_id=pt[y.driveItemId])})}catch{}_=m,G(),M.length>0&&window.AlbumsWs&&AlbumsWs.undoEmptyState(Ht()),fe(),i.firstLoad(),F["@odata.nextLink"]?(v=F["@odata.nextLink"],b=async function(y){var D=await fetch(y,{headers:{Authorization:"Bearer "+S.cloudToken,Accept:"application/json"}});return D.status===401&&(S.cloudToken=null,await K(!0),D=await fetch(y,{headers:{Authorization:"Bearer "+S.cloudToken,Accept:"application/json"}})),D}):v=null}o&&o.album_id===e.album_id?(_=m,G(),fe()):(_=m,G())}_.length===0&&(W.style.display="",J&&(J.style.display="none"));var ni=_.map(function(y){return y.driveItemId}).filter(Boolean);if(ni.length>0&&window.ViewLib&&window.ViewLib.SQL)try{var In=await window.ViewLib.SQL.named("gallery_cloud_enrich",{params:{item_ids:JSON.stringify(ni)}});In.forEach(function(y){if(y.driveItemId){var D=_.find(function(ai){return ai&&ai.driveItemId===y.driveItemId});D&&(D.isFavorite=!!y.isFavorite,D.isShared=!!y.isShared,D.isLocalOnly=!!y.isLocalOnly,D.fileSystemId=y.fileSystemId||null,D.placeholderState=typeof y.placeholderState>"u"?null:y.placeholderState,D.originalItemUniqueId=y.originalItemUniqueId||null,D.siteId=y.siteId||null,D.listId=y.listId||null,D.listItemUniqueId=y.listItemUniqueId||null,y.driveId&&(D.driveId=y.driveId))}}),fe(),window.__detailEnriched=!0}catch{}_.length===0&&o&&o.album_id===e.album_id&&ve()}catch(y){console.error("Failed to load album photos:",y),Q.style.display="none",se.textContent=Od4Strings.t("albumsPhotosFailed"),se.style.display="",i.fail(y&&y.name||"UnknownError")}}var dt=new Set,dn=-1,sn=-1;function st(){var e=n&&n.selectedItems||dt,t=[],i=0,a=!0,s=!1,d=!1;e.forEach(function(u){var f=O.itemAt(u);if(f){var l=f.driveItemId||f.id;i<1e3&&t.push({id:l}),f.isFavorite||(a=!1),f.isLocalOnly&&(s=!0),typeof l=="string"&&l.indexOf("temp!")===0&&(d=!0)}i++}),e.size===0&&(a=!1),sn=e.size,window.parent.postMessage({type:"selection-changed",count:e.size,items:t,allFavorited:a,anyLocalOnly:s,anyTemporaryItem:d},"*")}function ae(){if(dt.clear(),dn=-1,n){if(n.selectedIndex<0&&n.selectedItems.size>0){var e=-1;n.selectedItems.forEach(function(t){e=t}),n.selectedIndex=e}n.selectedItems.clear(),n.needsRender=!0}st()}function un(e){var t=!1;function i(){t||(t=!0,clearTimeout(s),window.removeEventListener("message",a),e())}function a(d){d.data&&d.data.type==="topbar-visible-applied"&&d.data.visible&&i()}window.addEventListener("message",a);var s=setTimeout(i,200)}function he(e){if(o){var t=!!(e&&(e.backNavigation||e.type==="back-requested"));t||(Ve=!0,ViewLib.Messages.releaseBackNavigationCover()),ae(),o=null,_=[],G(),zt(null),Yi(),window.parent.postMessage({type:"close-details-pane"},"*"),ge&&ge.disable(),document.documentElement.classList.remove("l2-immersive"),window.parent.postMessage({type:"set-topbar-visible",visible:!0},"*"),window.parent.postMessage({type:"_vp_l2_view",view:"AlbumL1"},"*"),be.settle(),be.setApiName("albumsview"),W.style.display="none",V.style.display="none",V.classList.remove("webgl-mode"),V.classList.remove("detail-empty-visible"),V.classList.remove("detail-deleted-visible"),de&&(de.style.display="none"),document.body.classList.remove("albums-shared-detail"),document.body.style.overflow="",un(function(){if(!(o||document.documentElement.classList.contains("l2-immersive"))){R.style.display="block";var i=document.getElementById("pageHeader");i&&(i.style.display=""),Ee.textContent=Od4Strings.t("navAlbums"),g?T&&(Ce?(T.clearPendingCovers(),ht()):T.drainPendingCovers()):z()}}),history.replaceState(null,"",window.location.pathname)}}function jt(){return n?Array.from(n.selectedItems).sort(function(e,t){return e-t}).map(function(e){return O.itemAt(e)}).filter(Boolean):[]}document.addEventListener("gallery-layout-change",function(e){Oe=e.detail.layout==="square"?"square":"river"}),document.addEventListener("gallery-zoom-change",function(e){_t=e.detail.zoomIndex,Qe=e.detail.rowHeight}),document.addEventListener("gallery-density-change",function(e){Xe=e.detail.density});async function Ue(){var e=jt(),t=e.map(function(r){return r.driveItemId});if(!(!t.length||!o||o._isShared)){var i=typeof Od4Shared<"u"&&Od4Shared.FileDimensions?Od4Shared.FileDimensions.extraDataForAll(e):void 0;ViewLib.Messages.sendVpAction("clickRemoveFromAlbum",{ksId:6069,extraData:Object.assign({count:t.length},i)});var a=await gn(t.length);if(a){var s=Date.now(),d=function(r,h,p){ViewLib.Messages.sendVpScenario("removeAlbumPhotos",{ksId:6069,duration:Date.now()-s,resultType:r,resultCode:h,extraData:Object.assign({},p!=null?{count:p}:null,i)})};try{var u=new Set(t);if(g){var f=await fetch(ce(o,"/oneDrive.manageItems"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:t.map(function(r){return{id:r,"@oneDrive.removed":"deleted"}})})});if(!f.ok&&f.status!==207)return}else if(S.cloudDriveId){var l=await Promise.all(t.map(function(r){return P("bundles/"+o.album_id+"/children/"+r,{method:"DELETE"})}));if(l.some(function(r){return!r.ok})){d("unexpected-failure","partial");return}}else{var f=await fetch("/api/albums/"+o.album_id+"/photos",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({driveItemIds:t}),_od4ApiName:"album.removePhotos"});if(!f.ok){d("unexpected-failure",String(f.status));return}}en(u),d("success",void 0,t.length)}catch(r){console.error("Ctx remove failed:",r),d("unexpected-failure",r&&r.name||"UnknownError")}}}}function Dn(e,t){return{apiPath:"albums/"+e,opts:{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaAlbum:{coverImageId:t}})}}}async function ut(e){if(!(!o||o._isShared)){ViewLib.Messages.sendVpAction("clickSetCoverPhoto",{ksId:6069,extraData:typeof Od4Shared<"u"&&Od4Shared.FileDimensions?Od4Shared.FileDimensions.extraDataFor(e):void 0});var t=o;try{var i=g?await fetch(ce(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaAlbum:{coverImageId:e.driveItemId}})}):await P("albums/"+t.album_id,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaAlbum:{coverImageId:e.driveItemId}}),_od4ApiName:"album.patchCover"});if(!i.ok)return;if(g){if(t.cover_drive_item_id=e.driveItemId||null,t.local_cover_thumbnail_id=e.thumbnail_id||null,T){var a=R.querySelector('[data-album-id="'+t.album_id+'"]');if(a){var s=a.querySelector(".album-card-link"),d=tt(t,null,"0ms"),u=d.querySelector(".album-card-link");s&&u&&(s.hasAttribute("aria-posinset")&&u.setAttribute("aria-posinset",s.getAttribute("aria-posinset")),s.hasAttribute("aria-setsize")&&u.setAttribute("aria-setsize",s.getAttribute("aria-setsize"))),s&&s.tabIndex===0&&me(d,!0),a.replaceWith(d),T.loadCoversOrDefer(d)}}e.thumbnail_id?fetch("/api/thumbnails/od4batch",{method:"POST",headers:{"Content-Type":ViewLib.ECS.jsonRequestContentType()},body:JSON.stringify({ids:[e.thumbnail_id]}),_od4ApiName:"thumbnail.batch"}).then(function(v){return v.arrayBuffer()}).then(function(v){Ft(v,t)}).catch(function(){t===o&&X(t)}):t===o&&X(t)}else{var f=Math.max(window.innerWidth,te.offsetHeight)*devicePixelRatio,l=Vi(f),r="c"+l+"x"+l,h=await P("items/"+e.driveItemId+"/thumbnails/0/"+r+"/content",{_od4ApiName:"thumbnail"}),p=h.url;if(h.ok){var c=await h.blob();Me(p,c),t===o&&Se(c)}t.cover_thumbnail_url=p,t.cover_image_id=e.driveItemId;var m=E.find(function(v){return v.album_id===t.album_id});m&&m!==t&&(m.cover_thumbnail_url=p,m.cover_image_id=e.driveItemId),P("items/"+e.driveItemId+"?select=image").then(function(v){if(v.ok)return v.json()}).then(function(v){v&&t===o&&At(A,v)}).catch(function(){})}}catch(v){console.error("Set cover failed:",v)}}}function cn(){if(!(!n||!n.selectedItems||n.selectedItems.size===0)&&typeof Od4CtxMenuActions=="object"){var e=n._ctxItemsForDispatch(n.selectedItems);e.length&&Od4CtxMenuActions.favorite(e,n._buildCtx())}}function mn(){if(!(!n||!n.selectedItems||n.selectedItems.size===0)&&typeof Od4CtxMenuActions=="object"){var e=n._ctxItemsForDispatch(n.selectedItems);e.length&&Od4CtxMenuActions.download(e[0])}}function fn(){if(!(!n||!n.selectedItems||n.selectedItems.size===0)&&typeof Od4CtxMenuActions=="object"){var e=n._ctxItemsForDispatch(n.selectedItems);e.length&&Od4CtxMenuActions.share(e,n._buildCtx())}}ViewLib.Messages.onMessageType("selection-action",function(e){if(e){if(e.action==="share")fn();else if(e.action==="favorite")cn();else if(e.action==="download")mn();else if(e.action==="remove-from-album")Ue();else if(e.action==="set-cover-photo"){var t=jt();if(t.length!==1||!t[0]||!t[0].driveItemId)return;ut(t[0])}}});var vn=window.OD4AlbumsReportConcern.init({reportDialog:mi,reportBannerEl:fi,reportCategories:vi,reportSubmitBtn:hi,reportDoneBtn:bi,reportFormState:pi,reportSentState:yi,reportFormActions:gi,reportSentActions:wi,reportErrorMsg:Ii,reportSpinner:_i,trapFocus:_trapFocus,ensureCloudAuth:K,getCloudToken:function(){return S.cloudToken},getDetailAlbum:function(){return o}}),hn=vn.showReportConcernDialog,bn=Od4Shared.AlbumsNameValidation.hasInvalidAlbumName,qe=null;function pn(){var e=U.value.trim();if(!e||!o||o._isShared||e===o.name)return;if(bn(e)){ct(),ViewLib.Messages.sendToastToShell(Od4Strings.t("albumsNameInvalid")||"Album name contains invalid characters.","error",3e3);return}if(qe===e)return;qe=e;var t=o,i=t.name;T&&g?T.updateAlbumCard({album_id:t.album_id,name:e}):(t.name=e,Te.textContent=e,Ee.textContent=e);var a=g?fetch(ce(t),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})}):Mi(t.driveId,"bundles/"+t.album_id,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e})}),s=a;function d(){T&&g?T.updateAlbumCard({album_id:t.album_id,name:i}):t.name=i,o?ct():z()}s.then(function(u){if(qe=null,u.ok){ViewLib.Messages.sendToastToShell(Od4Strings.t("albumsRenameSuccess")||"Album renamed","success",3e3);return}d(),u.status===409?ViewLib.Messages.sendToastToShell(Od4Strings.t("albumsNameConflict")||"An album with the same name already exists. Please choose a different name.","error",3e3):(ViewLib.Messages.sendToastToShell(Od4Strings.t("albumsRenameFailed")||"Failed to rename album","error",3e3),ViewLib.Messages.sendVpScenario("renameAlbum",{ksId:6551,resultType:"unexpected-failure",resultCode:"http-"+u.status}))}).catch(function(u){qe=null,d(),ViewLib.Messages.sendToastToShell(Od4Strings.t("albumsRenameFailed")||"Failed to rename album","error",3e3),ViewLib.Messages.sendVpScenario("renameAlbum",{ksId:6551,resultType:"unexpected-failure",resultCode:u&&u.name||"UnknownError"})})}function Wt(e){U.value=e,Te.textContent=e,Ee.textContent=e}function Jt(e){var t=document.getElementById("detailSharedBy");if(t)if(e&&e._isShared&&e.shared_by&&window.ViewLib&&window.ViewLib.Persona){var i=document.getElementById("detailSharedByCoin"),a=document.getElementById("detailSharedByLabel");i&&(i.textContent=ViewLib.Persona.getInitials(e.shared_by),i.dataset.ci=ViewLib.Persona.getColorIndex(e.shared_by)),a&&(a.textContent=Od4Strings.t("albumsSharedBy",[e.shared_by])),t.style.display=""}else t.style.display="none"}function ct(){o&&Wt(o.name||"")}U.addEventListener("blur",pn),U.addEventListener("keydown",function(e){e.key==="Enter"&&(e.preventDefault(),U.blur()),e.key==="Escape"&&(e.preventDefault(),ct(),U.blur())}),U.addEventListener("input",function(){Te.textContent=U.value}),ViewLib.Messages.bindBackButton(Je,function(){o&&he()}),ViewLib.Messages.onMessageType("back-navigation-cover-release-failed",function(){Ve=!1}),window.addEventListener("popstate",function(e){if(Ve){Ve=!1,history.replaceState(null,"",window.location.pathname);return}if(e.state&&e.state.albumId){var t=E.find(function(i){return i.album_id===e.state.albumId});if(t){Ne(t);return}}o&&he({backNavigation:!0})});var He=null,re=null,Ge=!1;function Ae(){He&&(He(),He=null);var e=pe.classList.contains("open");pe.classList.remove("open"),e&&(ViewLib.Messages.setViewModalOpen(!1),Ge?re&&(re.end("confirm"),re=null):(ViewLib.Messages.sendVpAction("dismissCreateAlbum",{ksId:6069}),re&&(re.abort("cancel"),re=null)),Ge=!1)}function Tn(){De.value="",pe.classList.add("open"),ViewLib.Messages.setViewModalOpen(!0);var e=pe.querySelector(".dialog-panel");e&&(He=_trapFocus(e)),setTimeout(function(){De.focus()},50),ViewLib.Messages.sendVpAction("openCreateAlbum",{ksId:6069}),Ge=!1,re=ViewLib.Messages.beginDialogScenario("createalbumdialog",{ksId:6069})}Si.addEventListener("click",function(){Ae()});var Kt=document.getElementById("createModalClose");Kt&&Kt.addEventListener("click",function(){Ae()});var Yt=document.getElementById("albumsEmptyCta");Yt&&Yt.addEventListener("click",function(){ViewLib.Messages.sendToShell({type:"open-create-album-modal"})}),We.addEventListener("click",function(){ViewLib.Messages.sendVpAction("clickCreateAlbum",{ksId:6069}),Xt()}),De.addEventListener("keydown",function(e){e.key==="Enter"&&(ViewLib.Messages.sendVpAction("clickCreateAlbum",{ksId:6069}),Xt()),e.key==="Escape"&&Ae()});function Qt(){return{isRampOn:function(){return g},strings:{albumsCreating:Od4Strings.t("albumsCreating"),albumsCreate:Od4Strings.t("albumsCreate"),ataCreateFailed:Od4Strings.t("ataCreateFailed"),albumsNameConflict:Od4Strings.t("albumsNameConflict"),albumsNameInvalid:Od4Strings.t("albumsNameInvalid"),albumsDeleteFailed:Od4Strings.t("albumsDeleteFailed")},getNameInputValue:function(){return De.value},setConfirmText:function(e){We.textContent=e},setConfirmDisabled:function(e){We.disabled=e},ensureCloudAuth:K,getCloudDriveId:function(){return S.cloudDriveId},cloudFetch:P,nucleusAlbumUrl:ce,sendToShellStatus:function(e){ViewLib.Messages.sendToShell({type:"status",text:e})},emitVpScenario:ViewLib.Messages.sendVpScenario,emitVpAction:ViewLib.Messages.sendVpAction,markConfirmed:function(){Ge=!0},closeCreateModal:Ae,getAutoRefresh:function(){return T},albumTypeOptions:window.OD4AlbumsGridMutations.albumTypeOptions,buildAlbumRecord:window.OD4AlbumsGridMutations.buildRecordFromRow,replaceAlbums:function(e,t){E=e,H=t},renderAlbumGrid:z,findOwnedAlbum:function(e){return E.find(function(t){return t.album_id===e})},showDeleteDialog:function(e){return yn(e)},legacyRemoveFromArray:function(e){E=E.filter(function(t){return t.album_id!==e})},isViewingAlbum:function(e){return!!(o&&o.album_id===e)},showAlbumGrid:he}}function Xt(){return window.OD4AlbumsActions.createAlbum(Qt())}function Zt(e){return window.OD4AlbumsActions.deleteAlbum(e,Qt())}var $t=window.OD4AlbumsConfirmationDialogs.init({deleteDialog:ui,removeFromAlbumDialog:ci,trapFocus:_trapFocus}),yn=$t.showDeleteDialog,gn=$t.showRemoveDialog;window.addEventListener("keydown",function(e){if(e.key==="Escape"){var t=document.getElementById("albumShareOverlay");if(t&&t.classList.contains("open")){nn();return}if(pe.classList.contains("open")){Ae();return}if(n&&n.selectedItems.size>0){ae();return}if(o){he();return}}var i=e.target&&e.target.closest&&e.target.closest("input,textarea");if((e.ctrlKey||e.metaKey)&&e.key==="a"&&!i&&(e.preventDefault(),o&&n)){for(var a=O.count(),s=0;s<a;s++)n.selectedItems.add(s);n.needsRender=!0,st()}if((e.key==="Delete"||e.key==="Backspace")&&o&&!i){var d=n&&n.selectedItems.size>0;d&&(e.preventDefault(),Ue())}}),ViewLib.ThemeSync.listenForShellThemeChanges(),window.addEventListener("message",function(e){if(e.data&&e.data.type==="albums-refresh"){if(g)return;Tt()}if(e.data&&e.data.type==="clear-selection"&&ae(),e.data&&e.data.type==="exit-l2-detail"&&o&&he(),e.data&&e.data.type==="restore-l2-detail"&&e.data.albumId){var t=e.data.albumId;if(o&&o.album_id===t)we=null;else{var i=nt(t);i?(we=null,Ne(i)):ft&&(we=t)}}if(e.data&&e.data.type==="focus-create-btn"){var a=document.getElementById("albumsNewAlbumBtn");a&&typeof a.focus=="function"&&(a.focus(),a.setAttribute("data-focus-create-returned",""))}});var mt=!1;document.addEventListener("scroll",function(){mt||(mt=!0,requestAnimationFrame(function(){mt=!1,ViewLib.Messages.sendToShell({type:"scroll-position",scrollTop:document.scrollingElement.scrollTop})}))},{passive:!0});var ft=!0,le=!0,Ce=!1,vt=!1;function ei(){return le&&!!R&&R.style.display!=="none"}function ht(){!Ce||vt||!g||!T||!T.reconcileFromDb||(vt=!0,Promise.resolve(T.reconcileFromDb()).then(function(e){e!==!1&&(Ce=!1)}).catch(function(){}).then(function(){vt=!1}))}window.addEventListener("message",function(e){!e||!e.data||e.data.type!=="nucleus-resync"||(Ce=!0,ei()&&ht())});var T=window.OD4AlbumsGridMutations?window.OD4AlbumsGridMutations.bootWs({isRampOn:function(){return g},isPageVisible:function(){return le},getAlbums:function(){return E},getSharedAlbums:function(){return H},getGridContainer:function(){return L},getAlbumGridEl:function(){return R},getSectionListEl:function(e){return Ui(e)},renumberSectionMenu:function(e){Vt(e)},buildCardHtml:kt,renderAlbumGrid:z,loadGridCovers:function(e){Mt(e),Rt(e)},patchAlbumCardText:Fi,getDetailAlbum:function(){return o},getDetailGallery:function(){return n},getDetailCount:function(){return O.count()},setAlbumEmptyState:ve,pickReplacementCover:rt,getAlbumDetailEl:function(){return V},getDetailEmptyEl:function(){return W},loadDetailHero:X,getDetailControlsEl:function(){return document.getElementById("detailControls")},getDetailScrollContentEl:function(){return J},createAlbumCard:function(e){return tt(e,null,"0ms")},getMyAlbumsSort:function(){return Ie},refreshDetailChrome:function(e){Wt(e.name||"")},renderDetailAlbumStatus:function(e){Pe(e)},renderDetailSharedBy:function(e){Jt(e)},parseAlbumPermissions:Et,exitToAlbumGrid:function(){he()},showAlbumDeletedState:function(){$i()},isInitInProgress:function(){return ft}}):null;window.addEventListener("message",function(e){if(e&&e.data&&e.data.type==="album-share-online-state"){on(!e.data.online);return}if(!(!e||!e.data||e.data.type!=="page-visibility")){var t=le;le=e.data.visible!==!1,n&&oe()&&(n._pageVisible=le,le&&n._schedulePendingFreshnessCallbacks&&n._schedulePendingFreshnessCallbacks()),!t&&le&&T&&(Ce&&ei()?(T.clearPendingCovers(),T.clearPendingFetches(),ht()):(T.drainPendingCovers(),T.flushPendingFetches()))}}),Tt()}();