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