Liferay.Loader.define("layout-taglib@16.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","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,itemSelectorSaveEvent:t,items:a=[],onItemsCountChange:l,multiSelection:d,selectedLayoutIds:u}){const[s,f]=(0,c.useState)(a),[y,p]=(0,c.useState)(new Set(u)),m=(0,c.useMemo)((()=>e?nodeByName(s,e):s),[s,e]),g=(0,c.useRef)(new Map),updateSelectedItems=(e,t,a)=>{t.has(e.id)?g.current.delete(e.id):g.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}),e.children&&a&&e.children.forEach((e=>updateSelectedItems(e,t,a)))},handleMultipleSelectionChange=(e,a,r)=>{if(a.toggle(e.id,{parentSelection:!1,selectionMode:r?"multiple-recursive":null}),updateSelectedItems(e,a,r),l&&l(g.current.size),!g.current.size)return;const n=Array.from(g.current.values());Liferay.fire(t,{data:n}),(0,o.getOpener)().Liferay.fire(t,{data:n})},handleSingleSelection=(e,a)=>{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(t,{data:r}),(0,o.getOpener)().Liferay.fire(t,{data:r}),requestAnimationFrame((()=>{a.toggle(e.id)}))},_onClick=(e,t,a,r)=>{e.preventDefault(),t.disabled?r.toggle(t.id):d?handleMultipleSelectionChange(t,a,e.shiftKey):handleSingleSelection(t,a)},_onKeyDown=(e,t,a)=>{" "!==e.key&&"Enter"!==e.key||(e.stopPropagation(),d?handleMultipleSelectionChange(t,a,e.shiftKey):handleSingleSelection(t,a))};return m.length?c.default.createElement("div",{className:"pt-3 px-3"},d&&c.default.createElement("p",{className:"mb-4",dangerouslySetInnerHTML:{__html:(0,o.sub)(Liferay.Language.get("press-x-to-select-or-deselect-a-parent-node-and-all-its-child-items"),'<kbd class="c-kbd c-kbd-light">⇧</kbd>')}}),c.default.createElement(r.TreeView,{items:m,onItemsChange:e=>f(e),onSelectionChange:e=>p(e),selectedKeys:y,selectionMode:d?"multiple":"single",showExpanderOnHover:!1},((e,t,a)=>c.default.createElement(r.TreeView.Item,{active:!1},c.default.createElement(r.TreeView.ItemStack,{active:!1,onClick:r=>_onClick(r,e,t,a),onKeyDown:a=>_onKeyDown(a,e,t)},d&&!e.disabled&&c.default.createElement(Checkbox,{checked:t.has(e.id),onChange:a=>handleMultipleSelectionChange(e,t,a.nativeEvent.shiftKey),onClick:e=>e.stopPropagation(),tabIndex:"-1"}),c.default.createElement(i.default,{symbol:e.icon}),c.default.createElement("div",{className:"d-flex"},c.default.createElement("span",{className:"flex-grow-0",title:e.url},e.name))),c.default.createElement(r.TreeView.Group,{items:e.children},(e=>c.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&&c.default.createElement(Checkbox,{checked:t.has(e.id),onChange:a=>handleMultipleSelectionChange(e,t,a.nativeEvent.shiftKey),onClick:e=>e.stopPropagation(),tabIndex:"-1"}),c.default.createElement(i.default,{symbol:e.icon}),c.default.createElement("div",{className:"d-flex"},c.default.createElement("span",{className:"flex-grow-0",title:e.url},e.name))))))))):c.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"),c=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}),[]);const Checkbox=e=>c.default.createElement(l.ClayCheckbox,e)}}));
//# sourceMappingURL=SelectLayoutTree.es.js.map