Liferay.Loader.define("layout-taglib@9.0.1/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","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.SelectLayoutTree=function({filter:t,followURLOnTitleClick:a,itemSelectorSaveEvent:u,items:c=[],multiSelection:d,selectedLayoutIds:f}){const[y,s]=(0,o.useState)(c),[p,m]=(0,o.useState)(new Set(f)),g=(0,o.useMemo)((()=>t?e(y,t):y),[y,t]),b=(0,o.useRef)(new Map),L=(e,t)=>{if(t.toggle(e.id),t.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(a)Liferay.Util.getOpener().document.location.href=e.url;else{const e=Array.from(b.current.values());Liferay.fire(u,{data:e}),Liferay.Util.getOpener().Liferay.fire(u,{data:e})}},h=(e,t)=>{const a={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(u,{data:a}),Liferay.Util.getOpener().Liferay.fire(u,{data:a}),requestAnimationFrame((()=>{t.toggle(e.id)}))},v=(e,t,r)=>{e.preventDefault(),a?Liferay.Util.getOpener().document.location.href=t.url:t.disabled||(d?L(t,r):h(t,r))},w=(e,t,a)=>{if(" "===e.key||"Enter"===e.key){if(e.stopPropagation(),t.disabled)return;d?L(t,a):h(t)}};return g.length>0?o.default.createElement(r.TreeView,{items:g,onItemsChange:e=>s(e),onSelectionChange:e=>m(e),selectedKeys:p,selectionMode:d?"multiple":"single",showExpanderOnHover:!1},((e,t)=>o.default.createElement(r.TreeView.Item,null,o.default.createElement(r.TreeView.ItemStack,{onClick:a=>v(a,e,t),onKeyDownCapture:a=>w(a,e,t)},d&&!e.disabled&&o.default.createElement(l.ClayCheckbox,{onChange:()=>L(e,t),tabIndex:"-1"}),o.default.createElement(i.default,{symbol:e.icon}),e.name),o.default.createElement(r.TreeView.Group,{items:e.children},(e=>o.default.createElement(r.TreeView.Item,{disabled:e.disabled,expanderDisabled:!1,onClick:a=>v(a,e,t),onKeyDownCapture:a=>w(a,e,t)},d&&!e.disabled&&o.default.createElement(l.ClayCheckbox,{onChange:()=>L(e,t),tabIndex:"-1"}),o.default.createElement(i.default,{symbol:e.icon}),e.name)))))):o.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=c(a("@frontend-taglib-clay$clayui/empty-state")),l=a("@frontend-taglib-clay$clayui/form"),i=c(a("@frontend-taglib-clay$clayui/icon")),o=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=u();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 u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function c(e){return e&&e.__esModule?e:{default:e}}const e=(e,t)=>e.reduce((function e(a,r){var n;return(null===(n=r.name)||void 0===n?void 0:n.toLowerCase().includes(t.toLowerCase()))?a.push(r):r.children&&a.concat(r.children.reduce(e,a)),a}),[])}}));
//# sourceMappingURL=SelectLayoutTree.es.js.map