(()=>{"use strict";var e={d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{openMediaPickerPopup:()=>p,useEffectAsync:()=>r,useUIVersion:()=>s});const t=window.wp.element,n=window.lodash,r=(e,o=[])=>{const r=(0,t.useRef)(e);r.current=e;const i=(0,t.useCallback)(((...e)=>r.current(...e)),[]);(0,t.useEffect)((()=>{let e=!0;const o=i((()=>e));return()=>{(0,n.isFunction)(o)&&o(),e=!1}}),[i,...o])},i=window.kubio.constants,l=window.wp.data,s=()=>{const e=(0,l.useSelect)((e=>{var o,t;return(null===(o=e(i.STORE_KEY))||void 0===o||null===(t=o.getUIVersion)||void 0===t?void 0:t.call(o))||1}),[]),{setUIVersion:o=n.noop}=(0,l.useDispatch)(i.STORE_KEY)||{};return{uiVersion:e,setUIVersion:o}},a=window.wp.i18n,{wp:c}=window,u=e=>["sizes","mime","type","subtype","id","url","alt","link","caption"].reduce(((o,t)=>(null!=e&&e.hasOwnProperty(t)&&(o[t]=e[t]),o)),{});let d=null;const p=(e,{multiple:o=!1,allowedTypes:t=["image"],title:n=(0,a.__)("Select","kubio"),mode:r=null}={})=>new Promise(((i,l)=>{var s,a;d&&(null===(s=d)||void 0===s||null===(a=s.remove)||void 0===a||a.call(s)),d=c.media({title:n,multiple:o,library:{type:t}}),d.on("select",(()=>{const e=d.state().get("selection").toJSON();i(o?e:e[0])})),d.on("update",(e=>{const t=d.state(),n=e||t.get("selection");n&&n.models.length&&i(o?n.models.map((e=>u(e.toJSON()))):u(n.models[0].toJSON()))})),d.on("update",(()=>{const o=d.content.get();if(o&&o.collection){const e=o.collection;e.toArray().forEach((e=>e.trigger("destroy",e))),e.mirroring._hasMore=!0,e.more()}r&&o.mode(r);const t=Array.isArray(e)?!(null==e||!e.length):!!e,n=Array.isArray(e)?e:[e];if(!t)return;const i=d.state().get("selection");n.forEach((e=>{i.add(c.media.attachment(e))}));var l;(l=n,c.media.query({order:"ASC",orderby:"post__in",post__in:l,posts_per_page:-1,query:!0,type:"image"})).more().done((function(){}))})),d.on("update",(()=>{l(null)})),d.open()}));(window.kubio=window.kubio||{}).coreHooks=o})();
