(()=>{"use strict";var e,l={8274:(e,l,i)=>{const a=window.wp.blocks,n=window.React,t=window.wp.i18n,o=window.wp.blockEditor,r=window.wp.components,s=window.wp.element,u=window.wp.apiFetch;var d=i.n(u);const c=JSON.parse('{"UU":"infinite-uploads/gallery"}');(0,a.registerBlockType)(c.UU,{edit:function({attributes:e,setAttributes:l}){const i=(0,o.useBlockProps)({className:"iu-gallery-editor-preview"}),{folderId:a,folderName:u,columns:c,imageSize:p,linkTo:m,orderby:f,order:_,lightbox:g,caption:b}=e,[v,h]=(0,s.useState)([]),[E,y]=(0,s.useState)(!0),[w,S]=(0,s.useState)(null),[C,k]=(0,s.useState)([]),[O,N]=(0,s.useState)(!1),[T,x]=(0,s.useState)(null);(0,s.useEffect)((()=>{d()({path:"/infinite-uploads/v1/gallery/folders"}).then((e=>{h(e),y(!1)})).catch((e=>{S(e.message||(0,t.__)("Failed to load folders.","infinite-uploads")),y(!1)}))}),[]),(0,s.useEffect)((()=>{a?(N(!0),x(null),d()({path:`/infinite-uploads/v1/gallery/images?folder_id=${a}&size=${p}&orderby=${f}&order=${_}&limit=12`}).then((e=>{k(e),N(!1)})).catch((e=>{x(e.message||(0,t.__)("Failed to load images.","infinite-uploads")),N(!1)}))):k([])}),[a,p,f,_]);const F=[{label:(0,t.__)("— Select a folder —","infinite-uploads"),value:0},...v.map((e=>({label:e.name,value:e.id})))];return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(o.InspectorControls,null,(0,n.createElement)(r.PanelBody,{title:(0,t.__)("Gallery Settings","infinite-uploads")},E?(0,n.createElement)(r.Spinner,null):(0,n.createElement)(r.SelectControl,{label:(0,t.__)("Folder","infinite-uploads"),value:a,options:F,onChange:e=>{const i=parseInt(e,10),a=v.find((e=>e.id===i));l({folderId:i,folderName:a?a.name:""})}}),(0,n.createElement)(r.RangeControl,{label:(0,t.__)("Columns","infinite-uploads"),value:c,onChange:e=>l({columns:e}),min:1,max:6}),(0,n.createElement)(r.SelectControl,{label:(0,t.__)("Image Size","infinite-uploads"),value:p,options:[{label:(0,t.__)("Thumbnail","infinite-uploads"),value:"thumbnail"},{label:(0,t.__)("Medium","infinite-uploads"),value:"medium"},{label:(0,t.__)("Large","infinite-uploads"),value:"large"},{label:(0,t.__)("Full Size","infinite-uploads"),value:"full"}],onChange:e=>l({imageSize:e})}),(0,n.createElement)(r.SelectControl,{label:(0,t.__)("Link To","infinite-uploads"),value:m,options:[{label:(0,t.__)("None","infinite-uploads"),value:"none"},{label:(0,t.__)("Media File","infinite-uploads"),value:"file"},{label:(0,t.__)("Attachment Page","infinite-uploads"),value:"attachment"}],onChange:e=>l({linkTo:e})}),(0,n.createElement)(r.SelectControl,{label:(0,t.__)("Order By","infinite-uploads"),value:f,options:[{label:(0,t.__)("Date","infinite-uploads"),value:"date"},{label:(0,t.__)("Title","infinite-uploads"),value:"title"},{label:(0,t.__)("Random","infinite-uploads"),value:"rand"}],onChange:e=>l({orderby:e})}),(0,n.createElement)(r.SelectControl,{label:(0,t.__)("Order","infinite-uploads"),value:_,options:[{label:(0,t.__)("Descending","infinite-uploads"),value:"DESC"},{label:(0,t.__)("Ascending","infinite-uploads"),value:"ASC"}],onChange:e=>l({order:e})}),(0,n.createElement)(r.ToggleControl,{label:(0,t.__)("Enable Lightbox","infinite-uploads"),help:(0,t.__)("Open full-size images in a PhotoSwipe lightbox.","infinite-uploads"),checked:g,onChange:e=>l({lightbox:e})}),(0,n.createElement)(r.ToggleControl,{label:(0,t.__)("Show Captions","infinite-uploads"),checked:b,onChange:e=>l({caption:e})}))),(0,n.createElement)("div",{...i},a?O?(0,n.createElement)("div",{className:"iu-gallery-editor-loading"},(0,n.createElement)(r.Spinner,null),(0,n.createElement)("span",null,(0,t.__)("Loading images…","infinite-uploads"))):T?(0,n.createElement)(r.Notice,{status:"error",isDismissible:!1},T):C.length?(0,n.createElement)("div",{className:`iu-gallery iu-gallery-columns-${c}`,style:{"--iu-columns":c}},C.map((e=>(0,n.createElement)("figure",{key:e.id,className:"iu-gallery-item"},(0,n.createElement)("img",{src:e.src,alt:e.alt,className:"iu-gallery-img"}))))):(0,n.createElement)("p",{className:"iu-gallery-editor-empty"},(0,t.sprintf)(/* translators: %s: folder name */ /* translators: %s: folder name */
(0,t.__)('No images found in "%s".',"infinite-uploads"),u||(0,t.__)("this folder","infinite-uploads"))):(0,n.createElement)(r.Placeholder,{icon:"format-gallery",label:(0,t.__)("IU Media Folder Gallery","infinite-uploads"),instructions:(0,t.__)("Select a media folder from the sidebar to display its images as a gallery.","infinite-uploads")},E&&(0,n.createElement)(r.Spinner,null),w&&(0,n.createElement)(r.Notice,{status:"error",isDismissible:!1},w))))},save:function(){return null}})}},i={};function a(e){var n=i[e];if(void 0!==n)return n.exports;var t=i[e]={exports:{}};return l[e](t,t.exports,a),t.exports}a.m=l,e=[],a.O=(l,i,n,t)=>{if(!i){var o=1/0;for(d=0;d<e.length;d++){for(var[i,n,t]=e[d],r=!0,s=0;s<i.length;s++)(!1&t||o>=t)&&Object.keys(a.O).every((e=>a.O[e](i[s])))?i.splice(s--,1):(r=!1,t<o&&(o=t));if(r){e.splice(d--,1);var u=n();void 0!==u&&(l=u)}}return l}t=t||0;for(var d=e.length;d>0&&e[d-1][2]>t;d--)e[d]=e[d-1];e[d]=[i,n,t]},a.n=e=>{var l=e&&e.__esModule?()=>e.default:()=>e;return a.d(l,{a:l}),l},a.d=(e,l)=>{for(var i in l)a.o(l,i)&&!a.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:l[i]})},a.o=(e,l)=>Object.prototype.hasOwnProperty.call(e,l),(()=>{var e={499:0,216:0};a.O.j=l=>0===e[l];var l=(l,i)=>{var n,t,[o,r,s]=i,u=0;if(o.some((l=>0!==e[l]))){for(n in r)a.o(r,n)&&(a.m[n]=r[n]);if(s)var d=s(a)}for(l&&l(i);u<o.length;u++)t=o[u],a.o(e,t)&&e[t]&&e[t][0](),e[t]=0;return a.O(d)},i=globalThis.webpackChunkinfinite_uploads=globalThis.webpackChunkinfinite_uploads||[];i.forEach(l.bind(null,0)),i.push=l.bind(null,i.push.bind(i))})();var n=a.O(void 0,[216],(()=>a(8274)));n=a.O(n)})();