Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.169/page_editor/plugins/fragments_and_widgets/components/TabCollection",["module","exports","require","@frontend-taglib-clay$clayui/icon","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../../app/config/constants/fragmentsDisplayStyles","../../../app/config/constants/listItemTypes","../../../app/config/index","../../../common/hooks/useSessionState","../hooks/useKeyboardNavigation","./TabItem"],(function(e,t,l){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=TabCollection;var a=_interopRequireDefault(l("@frontend-taglib-clay$clayui/icon")),n=_interopRequireDefault(l("liferay!frontend-js-react-web$classnames")),o=_interopRequireDefault(l("liferay!frontend-js-react-web$prop-types")),r=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 l={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=a?Object.getOwnPropertyDescriptor(e,n):null;o&&(o.get||o.set)?Object.defineProperty(l,n,o):l[n]=e[n]}l.default=e,t&&t.set(e,l);return l}(l("liferay!frontend-js-react-web$react")),i=l("../../../app/config/constants/fragmentsDisplayStyles"),s=l("../../../app/config/constants/listItemTypes"),c=l("../../../app/config/index"),u=l("../../../common/hooks/useSessionState"),d=_interopRequireDefault(l("../hooks/useKeyboardNavigation")),f=_interopRequireDefault(l("./TabItem"));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 e="highlighted";function TabCollection({collection:t,displayStyle:l,initialOpen:a,isSearchResult:n}){const[o,i]=(0,u.useSessionState)("".concat(c.config.portletNamespace,"_fragment-collection_").concat(t.collectionId,"_open"),a),s=(0,r.useRef)();return r.default.createElement(TabCollectionCollapse,{collapseRef:s,isSearchResult:n,open:o,setOpen:i,title:t.label},t.collections&&t.collections.map(((e,t)=>r.default.createElement(TabCollection,{collection:e,displayStyle:l,initialOpen:!1,isSearchResult:n,key:t}))),r.default.createElement("ul",{"aria-orientation":"vertical",className:"list-unstyled page-editor__fragments-widgets__tab-collection-".concat(l," pb-2 w-100"),role:"menu"},t.children.map(((a,n)=>{var o;return r.default.createElement(r.default.Fragment,{key:a.itemId},r.default.createElement(f.default,{displayStyle:l,item:a,key:a.itemId,onRemoveHighlighted:()=>(l=>{var a,n;if(t.collectionId!==e)return;const o=null===(a=s.current)||void 0===a?void 0:a.querySelectorAll("li");1===o.length&&s.current.nextSibling.querySelector("button").focus();null===(n=o[0===l?1:l-1])||void 0===n||n.focus()})(n)}),(null===(o=a.portletItems)||void 0===o?void 0:o.length)&&r.default.createElement(TabPortletItems,{item:a}))}))))}TabCollection.proptypes={collection:o.default.shape({children:o.default.array,collectionId:o.default.string,label:o.default.string}).isRequired,displayStyle:o.default.oneOf(Object.values(i.FRAGMENTS_DISPLAY_STYLES)),isSearchResult:o.default.bool,open:o.default.bool};const TabPortletItems=({item:e})=>r.default.createElement("ul",{className:"d-flex flex-wrap list-unstyled w-100"},e.portletItems.map(((e,t)=>r.default.createElement(f.default,{item:e,key:t}))));function TabCollectionCollapse({children:e,collapseRef:t,isSearchResult:l,open:o,setOpen:i,title:c}){const[u,f]=(0,r.useState)(!0),p=l?u:o,y=l?f:i,{isTarget:m,setElement:g}=(0,d.default)({handleOpen:y,type:s.LIST_ITEM_TYPES.header});return r.default.createElement("li",{className:"page-editor__collapse panel-group panel-group-flush",ref:t,role:"none"},r.default.createElement("button",{"aria-expanded":p?"true":"false","aria-haspopup":"menu",className:(0,n.default)("btn","btn-unstyled","collapse-icon","sheet-subtitle",{collapsed:!p}),onClick:()=>y(!p),ref:g,role:"menuitem",tabIndex:m?0:-1,type:"button"},r.default.createElement("span",{className:"c-inner text-truncate",tabIndex:-1},c,r.default.createElement("span",{className:"text-secondary collapse-icon-".concat(p?"open":"closed")},r.default.createElement(a.default,{symbol:p?"angle-down":"angle-right"})))),p&&e)}TabPortletItems.proptypes={data:o.default.shape({instanceable:o.default.bool,portletId:o.default.string,portletItemId:o.default.string,used:o.default.bool}).isRequired,disabled:o.default.bool,icon:o.default.string,itemId:o.default.string,label:o.default.string,portletItems:o.default.array,preview:o.default.string,type:o.default.string},TabCollectionCollapse.proptypes={open:o.default.bool.isRequired,setOpen:o.default.func.isRequired,title:o.default.string.isRequired}}}));
//# sourceMappingURL=TabCollection.js.map