((e,r)=>{"use strict";const t=e.i18n.__;var a=e.blocks.registerBlockType;const s=e.serverSideRender,{createElement:o,Component:i,Fragment:n}=e.element,{Panel:l,PanelBody:d,SelectControl:m,RangeControl:p}=e.components,c=e.blockEditor.InspectorControls;class u extends i{constructor(){super(...arguments),this.state={folders:[],imageSizes:[]}}processData(e,t,a={}){const s=r.Deferred();return e=r.ajax({url:MediaCommanderGalleryBlock.api.url+"/"+e,type:"GET"==t?"GET":"POST",cache:!1,dataType:"json",contentType:"application/json",headers:{"X-WP-Nonce":MediaCommanderGalleryBlock.api.nonce,"X-HTTP-Method-Override":t},data:"GET"===t?a:JSON.stringify(a)}).done(e=>{e&&e.success?s.resolve(e.data):s.reject()}).fail(()=>{s.reject()}).always(()=>{}),{...s.promise(),abort:e.abort}}getData(e,t={}){return this.processData(e,"GET",t)}componentDidMount(){this.getData("folders",{type:"attachment"}).done(e=>{var t=[{value:"",label:"None"}];!function e(t,a,s){for(const r of t)s.push({value:r.id,label:"-".repeat(a)+(a?" ":"")+r.title}),r.items&&r.items.length&&e(r.items,a+1,s)}(e&&void 0!==e.folders?e.folders:e,0,t),this.setState({folders:t})});const t=MediaCommanderGalleryBlock.data.imageSizes;this.setState({imageSizes:Object.keys(t).map(e=>({value:e,label:t[e]}))})}render(){return o(n,{},o(c,{},o(l,{},o(d,{title:t("Gallery Settings"),initialOpen:!0},o(m,{label:t("Folder"),value:this.props.attributes.folder,options:this.state.folders,onChange:e=>{this.props.setAttributes({folder:e})}}),o(p,{label:t("Columns"),value:this.props.attributes.columns,min:1,max:12,onChange:e=>{this.props.setAttributes({columns:e})}}),o(p,{label:t("Max Items"),value:this.props.attributes.max,min:0,onChange:e=>{this.props.setAttributes({max:e})}}),o(m,{label:t("Image Size"),value:this.props.attributes.imageSize,options:this.state.imageSizes,onChange:e=>{this.props.setAttributes({imageSize:e})}})))),o(s,{block:"mediacommander/image-gallery",attributes:this.props.attributes}))}}class h extends i{render(){return null}}a("mediacommander/image-gallery",{edit:u,save:h})})(window.wp,window.jQuery);