Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.132/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 n=a("@frontend-taglib-clay$clayui/core"),r=f(a("@frontend-taglib-clay$clayui/empty-state")),l=a("@frontend-taglib-clay$clayui/form"),o=(f(a("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=i();if(t&&t.has(e))return t.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var l=n?Object.getOwnPropertyDescriptor(e,r):null;l&&(l.get||l.set)?Object.defineProperty(a,r,l):a[r]=e[r]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"))),c=a("../contexts/StoreContext");function i(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return i=function(){return e},e}function f(e){return e&&e.__esModule?e:{default:e}}const e=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},s=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")}],u=(e,t=[],a)=>e?a.filter((e=>!t.includes(e))):t,m=(e,t)=>e.reduce((function e(a,n){var r;return(null===(r=n.name)||void 0===r?void 0:r.toLowerCase().includes(t.toLowerCase()))?a.push(n):n.children&&a.concat(n.children.reduce(e,a)),a}),[]);var d=({dropZoneConfig:t,onSelectedFragment:a})=>{const i=(0,c.useSelector)((e=>e.fragments)),f=(0,o.useMemo)((()=>e(i)),[i]),d=void 0===t.allowNewFragmentEntries||null===t.allowNewFragmentEntries||t.allowNewFragmentEntries,g=t.fragmentEntryKeys||[],y=(0,o.useMemo)((()=>s(i)),[i]),[p,w]=(0,o.useState)(d),[h]=(0,o.useState)(u(p,g,f)),[b,E]=(0,o.useState)(y),[v,C]=(0,o.useState)(new Set(h)),x=new Set(["lfr-all-fragments-id"].concat(h));(0,o.useEffect)((()=>{const e=u(p,[...v],f);a({allowNewFragmentEntries:p,selectedFragments:e})}),[v,p,f,a]);const L=(e,t,a)=>{e.preventDefault(),a.toggle(t.id)},_=(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 E(y);const a=new Set(m(y,t));E(a.size?[...a]:[])},placeholder:"".concat(Liferay.Language.get("search"),"..."),sizing:"sm",type:"text"}),b.length?o.default.createElement("div",{className:"mb-2 page-editor__allowed-fragment__tree pl-2"},o.default.createElement(n.TreeView,{defaultExpandedKeys:x,items:b,nestedKey:"children",onItemsChange:E,onSelectionChange:C,selectedKeys:v,selectionMode:"multiple-recursive",showExpanderOnHover:!1},((e,t)=>o.default.createElement(n.TreeView.Item,null,o.default.createElement(n.TreeView.ItemStack,{onClick:a=>L(a,e,t),onKeyDown:a=>_(a,e,t)},o.default.createElement(l.ClayCheckbox,{label:e.name,tabIndex:-1})),o.default.createElement(n.TreeView.Group,{items:e.children},(e=>o.default.createElement(n.TreeView.Item,{onClick:a=>L(a,e,t),onKeyDown:a=>_(a,e,t)},o.default.createElement(l.ClayCheckbox,{label:e.name,tabIndex:-1})))))))):o.default.createElement(r.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:p,label:Liferay.Language.get("select-new-fragments-automatically"),onChange:e=>{w(e.target.checked)}})))};t.default=d}}));
//# sourceMappingURL=AllowedFragmentSelectorTree.js.map