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