Liferay.Loader.define("layout-taglib@13.0.5/select_layout/js/SelectLayoutTree.es",["module","exports","require","@frontend-taglib-clay$clayui/core","@frontend-taglib-clay$clayui/empty-state","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","frontend-js-web","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.SelectLayoutTree=function SelectLayoutTree({filter:e,followURLOnTitleClick:t,itemSelectorSaveEvent:a,items:c=[],multiSelection:d,selectedLayoutIds:f}){const[s,y]=(0,u.useState)(c),[m,p]=(0,u.useState)(new Set(f)),g=(0,u.useMemo)((()=>e?nodeByName(s,e):s),[s,e]),b=(0,u.useRef)(new Map),handleMultipleSelectionChange=(e,r)=>{if(r.toggle(e.id),r.has(e.id)?b.current.delete(e.id):b.current.set(e.id,{groupId:e.groupId,id:e.id,layoutId:e.layoutId,name:e.value,privateLayout:e.privateLayout,returnType:e.returnType,title:e.name,value:e.payload}),b.current.size)if(t)(0,o.getOpener)().document.location.href=e.url;else{const e=Array.from(b.current.values());Liferay.fire(a,{data:e}),(0,o.getOpener)().Liferay.fire(a,{data:e})}},handleSingleSelection=(e,t)=>{const r={groupId:e.groupId,id:e.id,layoutId:e.layoutId,name:e.value,privateLayout:e.privateLayout,returnType:e.returnType,title:e.name,value:e.payload};Liferay.fire(a,{data:r}),(0,o.getOpener)().Liferay.fire(a,{data:r}),requestAnimationFrame((()=>{t.toggle(e.id)}))},_onClick=(e,a,r,n)=>{e.preventDefault(),t?(0,o.getOpener)().document.location.href=a.url:a.disabled?n.toggle(a.id):d?handleMultipleSelectionChange(a,r):handleSingleSelection(a,r)},_onKeyDown=(e,t,a)=>{" "!==e.key&&"Enter"!==e.key||(e.stopPropagation(),d?handleMultipleSelectionChange(t,a):handleSingleSelection(t,a))};return g.length?u.default.createElement(r.TreeView,{items:g,onItemsChange:e=>y(e),onSelectionChange:e=>p(e),selectedKeys:m,selectionMode:d?"multiple":"single",showExpanderOnHover:!1},((e,t,a)=>u.default.createElement(r.TreeView.Item,{active:!1},u.default.createElement(r.TreeView.ItemStack,{active:!1,onClick:r=>_onClick(r,e,t,a),onKeyDown:a=>_onKeyDown(a,e,t)},d&&!e.disabled&&u.default.createElement(l.ClayCheckbox,{onChange:()=>handleMultipleSelectionChange(e,t),tabIndex:"-1"}),u.default.createElement(i.default,{symbol:e.icon}),u.default.createElement("div",{className:"d-flex"},u.default.createElement("span",{className:"flex-grow-0",title:e.url},e.name))),u.default.createElement(r.TreeView.Group,{items:e.children},(e=>u.default.createElement(r.TreeView.Item,{disabled:e.disabled,expanderDisabled:!1,onClick:a=>_onClick(a,e,t),onKeyDown:a=>_onKeyDown(a,e,t)},d&&!e.disabled&&u.default.createElement(l.ClayCheckbox,{onChange:()=>handleMultipleSelectionChange(e,t),tabIndex:"-1"}),u.default.createElement(i.default,{symbol:e.icon}),u.default.createElement("div",{className:"d-flex"},u.default.createElement("span",{className:"flex-grow-0",title:e.url},e.name)))))))):u.default.createElement(n.default,{description:Liferay.Language.get("try-again-with-a-different-search"),imgSrc:"".concat(themeDisplay.getPathThemeImages(),"/states/search_state.gif"),small:!0,title:Liferay.Language.get("no-results-found")})};var r=a("@frontend-taglib-clay$clayui/core"),n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/empty-state")),l=a("@frontend-taglib-clay$clayui/form"),i=_interopRequireDefault(a("@frontend-taglib-clay$clayui/icon")),o=a("frontend-js-web"),u=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 a={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var l=r?Object.getOwnPropertyDescriptor(e,n):null;l&&(l.get||l.set)?Object.defineProperty(a,n,l):a[n]=e[n]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"));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}}const nodeByName=(e,t)=>e.reduce((function reducer(e,a){var r;return(null===(r=a.name)||void 0===r?void 0:r.toLowerCase().includes(t.toLowerCase()))?e.push(a):a.children&&e.concat(a.children.reduce(reducer,e)),e}),[])}}));
//# sourceMappingURL=SelectLayoutTree.es.js.map