Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.141/page_editor/app/components/AllowedFragmentSelectorTree",["module","exports","require","@frontend-taglib-clay$clayui/core","@frontend-taglib-clay$clayui/empty-state","@frontend-taglib-clay$clayui/form","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../contexts/StoreContext"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=a("@frontend-taglib-clay$clayui/core"),n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/empty-state")),l=a("@frontend-taglib-clay$clayui/form"),o=(_interopRequireDefault(a("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 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"))),i=a("../contexts/StoreContext");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 toFragmentEntryKeysArray=e=>{const t=[];return e.forEach((e=>{e.fragmentEntries.forEach((e=>t.push(e.fragmentEntryKey))),t.push(e.fragmentCollectionId)})),t.push("lfr-all-fragments-id"),t},toNodes=e=>[{children:e.filter((e=>"layout-elements"!==e.fragmentCollectionId&&"highlighted"!==e.fragmentCollectionId)).map((e=>({children:e.fragmentEntries.filter((e=>e.fragmentEntryKey&&e.name)).map((e=>({id:e.fragmentEntryKey,name:e.name}))),expanded:!1,id:e.fragmentCollectionId,name:e.name}))),expanded:!0,id:"lfr-all-fragments-id",name:Liferay.Language.get("all-fragments")}],getSelectedNodeIds=(e,t=[],a)=>e?a.filter((e=>!t.includes(e))):t,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}),[]);var _default=({dropZoneConfig:e,onSelectedFragment:t})=>{const a=(0,i.useSelector)((e=>e.fragments)),c=(0,o.useMemo)((()=>toFragmentEntryKeysArray(a)),[a]),d=void 0===e.allowNewFragmentEntries||null===e.allowNewFragmentEntries||e.allowNewFragmentEntries,u=e.fragmentEntryKeys||[],f=(0,o.useMemo)((()=>toNodes(a)),[a]),[s,g]=(0,o.useState)(d),[m]=(0,o.useState)(getSelectedNodeIds(s,u,c)),[y,p]=(0,o.useState)(f),[h,w]=(0,o.useState)(new Set(m)),b=new Set(["lfr-all-fragments-id"].concat(m));(0,o.useEffect)((()=>{const e=getSelectedNodeIds(s,[...h],c);t({allowNewFragmentEntries:s,selectedFragments:e})}),[h,s,c,t]);const _onClick=(e,t,a)=>{e.preventDefault(),a.toggle(t.id)},_onKeyDown=(e,t,a)=>{" "!==e.key&&"Enter"!==e.key||(e.preventDefault(),a.toggle(t.id))};return o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{className:"px-4"},o.default.createElement(l.ClayInput,{className:"mb-4",onChange:e=>{const t=e.target.value;if(!t)return void p(f);const a=new Set(nodeByName(f,t));p(a.size?[...a]:[])},placeholder:"".concat(Liferay.Language.get("search"),"..."),sizing:"sm",type:"text"}),y.length?o.default.createElement("div",{className:"mb-2 page-editor__allowed-fragment__tree pl-2"},o.default.createElement(r.TreeView,{defaultExpandedKeys:b,items:y,nestedKey:"children",onItemsChange:p,onSelectionChange:w,selectedKeys:h,selectionMode:"multiple-recursive",showExpanderOnHover:!1},((e,t)=>o.default.createElement(r.TreeView.Item,null,o.default.createElement(r.TreeView.ItemStack,{onClick:a=>_onClick(a,e,t),onKeyDown:a=>_onKeyDown(a,e,t)},o.default.createElement(l.ClayCheckbox,{label:e.name,tabIndex:-1})),o.default.createElement(r.TreeView.Group,{items:e.children},(e=>o.default.createElement(r.TreeView.Item,{onClick:a=>_onClick(a,e,t),onKeyDown:a=>_onKeyDown(a,e,t)},o.default.createElement(l.ClayCheckbox,{label:e.name,tabIndex:-1})))))))):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")})),o.default.createElement("div",{className:"page-editor__allowed-fragment__new-fragments-checkbox px-4 py-3"},o.default.createElement(l.ClayCheckbox,{"aria-label":Liferay.Language.get("select-new-fragments-automatically"),checked:s,label:Liferay.Language.get("select-new-fragments-automatically"),onChange:e=>{g(e.target.checked)}})))};t.default=_default}}));
//# sourceMappingURL=AllowedFragmentSelectorTree.js.map