Liferay.Loader.define("item-selector-taglib@5.2.21/item_selector_preview/js/ItemSelectorPreview.es",["module","exports","require","@liferay/frontend-js-react-web","item-selector-taglib","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","liferay!frontend-js-react-web$react-dom","./Carousel.es","./Footer.es","./Header.es","../../css/item_selector_preview.scss"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r("@liferay/frontend-js-react-web"),a=r("item-selector-taglib"),o=(d(r("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=s();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var o=n?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(r,a,o):r[a]=e[a]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),i=d(r("liferay!frontend-js-react-web$react-dom")),l=d(r("./Carousel.es")),c=d(r("./Footer.es")),u=d(r("./Header.es"));function s(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return s=function(){return e},e}function d(e){return e&&e.__esModule?e:{default:e}}function f(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r("../../css/item_selector_preview.scss");const e={ESC:27,LEFT:37,RIGTH:39},b=()=>{},w=({mimeType:e,type:t})=>"image"===t||Boolean(null==e?void 0:e.match(/image.*/)),g=({container:t,currentIndex:r=0,editImageURL:s,handleClose:d=b,handleSelectedItem:f,headerTitle:y,itemReturnType:m,items:v,reloadOnHide:h=!1})=>{const[O,j]=(0,o.useState)(r),[E,I]=(0,o.useState)(),[P,k]=(0,o.useState)(w(v[r])),[C,S]=(0,o.useState)(v),[L,_]=(0,o.useState)(h),T=C[O],R=o.default.createRef(),D=(0,n.useIsMounted)(),M=(0,o.useCallback)((()=>{d(),t&&i.default.unmountComponentAtNode(t)}),[t,d]),N=(0,o.useCallback)((()=>{C.length>1&&j((e=>e===C.length-1?0:e+1))}),[C.length]),x=(0,o.useCallback)((()=>{C.length>1&&j((e=>{const t=C.length-1;return 0===e?t:e-1}))}),[C.length]),$=(0,o.useCallback)((t=>{if(D())switch(t.which||t.keyCode){case e.LEFT:x();break;case e.RIGTH:N();break;case e.ESC:t.preventDefault(),t.stopPropagation(),M()}}),[M,N,x,D]),F=(0,o.useCallback)((e=>{if(D()){const t=[...C];t[O]=p(p({},T),e),(e=>{S(e),_(!0)})(t)}}),[T,O,D,C]);return(0,o.useEffect)((()=>{document.documentElement.addEventListener("keydown",$);const e=Liferay.on("updateCurrentItem",F);return Liferay.component("ItemSelectorPreview",g),()=>{document.documentElement.removeEventListener("keydown",$),Liferay.detach(e),Liferay.component("ItemSelectorPreview",null)}}),[$,F]),(0,o.useEffect)((()=>{const e=R.current;return e&&Liferay.SideNavigation.initialize(e,{container:".sidenav-container",position:"right",typeMobile:"fixed",width:"320px"}),()=>{Liferay.SideNavigation.destroy(e)}}),[R]),(0,o.useEffect)((()=>{k(w(T))}),[T]),o.default.createElement("div",{className:"fullscreen item-selector-preview"},o.default.createElement(u.default,{disabledAddButton:!T.url,handleClickAdd:()=>{f(T)},handleClickBack:()=>{if(M(),L){const e=window.frameElement;e&&e.contentWindow.location.reload()}},handleClickEdit:()=>{I(!0)},headerTitle:y,infoButtonRef:R,showEditIcon:P,showInfoIcon:!!T.metadata,showNavbar:!E}),E?o.default.createElement(a.ImageEditor,{imageId:T.fileEntryId||T.fileentryid,imageSrc:T.url,itemReturnType:m,onCancel:()=>{I(!1)},onSave:({file:e,success:t})=>{if(t){const t=p(p({},T),{},{fileEntryId:e.fileEntryId,groupId:e.groupId,title:e.title,url:e.url,uuid:e.uuid,value:e.resolvedValue});if(!t.value){const e={fileEntryId:t.fileEntryId,groupId:t.groupId,title:t.title,type:t.type,url:t.url,uuid:t.uuid};t.value=JSON.stringify(e)}I(!1),M(),f(t)}},saveURL:s}):o.default.createElement(o.default.Fragment,null,o.default.createElement(l.default,{currentItem:T,handleClickNext:N,handleClickPrevious:x,isImage:P,showArrows:C.length>1}),o.default.createElement(c.default,{currentIndex:O,title:T.title,totalItems:C.length})))};var m=g;t.default=m}}));
//# sourceMappingURL=ItemSelectorPreview.es.js.map