Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.132/page_editor/app/components/fragment-configuration-fields/TargetCollectionsField",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/drop-down","@frontend-taglib-clay$clayui/form","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$react","../../../core/hooks/useId","../../config/constants/layoutDataItemTypes","../../contexts/ControlsContext","../../contexts/StoreContext","../../utils/isEmptyArray","../../utils/isLayoutDataItemDeleted"],(function(e,t,l){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.selectConfiguredCollectionDisplays=function(e){return Object.values(e.layoutData.items).filter((t=>{var l;return t.type===s.LAYOUT_DATA_ITEM_TYPES.collection&&(null===(l=t.config)||void 0===l?void 0:l.collection)&&!!Object.keys(t.config.collection).length&&!(0,m.isLayoutDataItemDeleted)(e.layoutData,t.itemId)}))},t.TargetCollectionsField=function({enableCompatibleCollections:e=!1,filterableCollections:t,onValueSelect:l,value:s}){const[f,m]=(0,i.useState)(!1),g=(0,c.useId)(),[y,p]=(0,i.useState)(s||[]),v=(0,u.useHoverItem)(),C=(0,d.useSelectorCallback)((e=>{return y.length?1===y.length?null===(t=e.layoutData.items[y[0]])||void 0===t||null===(l=t.config)||void 0===l||null===(a=l.collection)||void 0===a?void 0:a.title:Liferay.Language.get("multiple"):"";var t,l,a}),[y]),h=Object.values(t).map((a=>{const n=y.includes(a.itemId);return{checked:n,disabled:e&&!n&&b({filterableCollections:t,itemId:a.itemId,targetCollections:y}),label:a.config.collection.title,onChange:e=>((e,t)=>{const a=y.includes(e);let n=y;t&&!a?(n=[...y,e],p(n),l("targetCollections",n)):a&&(n=y.filter((t=>t!==e)),p(n),l("targetCollections",n))})(a.itemId,e),type:"checkbox",value:a.itemId}}));return i.default.createElement(o.default.Group,{className:"mt-1"},i.default.createElement("label",{htmlFor:g},Liferay.Language.get("target-collection")),i.default.createElement(n.default,{active:f,id:g,menuElementAttrs:{containerProps:{className:"cadmin page-editor__target-collections-field"}},onActiveChange:m,trigger:i.default.createElement(a.default,{"aria-label":Liferay.Language.get("select"),className:"bg-light font-weight-normal form-control-select text-left w-100",displayType:"secondary",small:!0},C?i.default.createElement("span",{className:"text-dark"},C):Liferay.Language.get("select"))},e&&Object.keys(t).length>1&&i.default.createElement(n.default.Help,{className:"pt-3 px-3"},Liferay.Language.get("multiple-selection-must-have-at-least-one-filter-in-common")),h.map((e=>i.default.createElement("label",{className:(0,r.default)("d-flex dropdown-item",{disabled:e.disabled}),key:e.value,onMouseLeave:()=>v(null),onMouseOver:()=>v(e.value)},i.default.createElement(o.ClayCheckbox,{checked:e.checked,disabled:e.disabled,onChange:e.onChange}),i.default.createElement("span",{className:"font-weight-normal ml-2"},e.label))))))};var a=p(l("@frontend-taglib-clay$clayui/button")),n=p(l("@frontend-taglib-clay$clayui/drop-down")),o=y(l("@frontend-taglib-clay$clayui/form")),r=p(l("liferay!frontend-js-react-web$classnames")),i=y(l("liferay!frontend-js-react-web$react")),c=l("../../../core/hooks/useId"),s=l("../../config/constants/layoutDataItemTypes"),u=l("../../contexts/ControlsContext"),d=l("../../contexts/StoreContext"),f=p(l("../../utils/isEmptyArray")),m=l("../../utils/isLayoutDataItemDeleted");function g(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return g=function(){return e},e}function y(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=g();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]}return l.default=e,t&&t.set(e,l),l}function p(e){return e&&e.__esModule?e:{default:e}}function b({filterableCollections:e,itemId:t,targetCollections:l}){var a;if((0,f.default)(l))return!1;const n=(null===(a=e[t])||void 0===a?void 0:a.supportedFilters)||[],o=l.map((t=>e[t].supportedFilters));return!n.some((e=>o.every((t=>t.includes(e)))))}}}));
//# sourceMappingURL=TargetCollectionsField.js.map