Liferay.Loader.define("asset-taglib@8.0.17/asset_categories_selector/AssetVocabularyCategoriesSelector.es",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/multi-select","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=m(a("@frontend-taglib-clay$clayui/button")),n=f(a("@frontend-taglib-clay$clayui/form")),r=m(a("@frontend-taglib-clay$clayui/icon")),u=f(a("@frontend-taglib-clay$clayui/multi-select")),c=a("@liferay/frontend-js-react-web"),i=m(a("liferay!frontend-js-react-web$classnames")),o=a("frontend-js-web"),s=(m(a("liferay!frontend-js-react-web$prop-types")),f(a("liferay!frontend-js-react-web$react")));function d(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return d=function(){return e},e}function f(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=d();if(t&&t.has(e))return t.get(e);var a={},l=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var r=l?Object.getOwnPropertyDescriptor(e,n):null;r&&(r.get||r.set)?Object.defineProperty(a,n,r):a[n]=e[n]}return a.default=e,t&&t.set(e,a),a}function m(e){return e&&e.__esModule?e:{default:e}}var y=function({eventName:e,id:t,isValid:a=!0,groupIds:d=[],inputName:f,label:m,onSelectedItemsChange:y=(()=>{}),portletURL:p,required:b,selectedItems:g=[],singleSelect:v,sourceItemsVocabularyIds:h=[],useFallbackInput:j}){const[L,I]=(0,s.useState)(""),[w,E]=(0,s.useState)([]),[k,C]=(0,s.useState)([]),S=(0,c.usePrevious)(L);return(0,s.useEffect)((()=>{L&&L!==S&&(0,o.fetch)("".concat(window.location.origin).concat(themeDisplay.getPathContext(),"/api/jsonws/invoke"),{body:new URLSearchParams({cmd:JSON.stringify({"/assetcategory/search":{"-obc":null,end:20,groupIds:d,name:"%".concat(L.toLowerCase(),"%"),start:0,vocabularyIds:h}}),p_auth:Liferay.authToken}),method:"POST"}).then((e=>e.json())).then((e=>C(e)))}),[d,L,S,h]),s.default.createElement("div",{className:"field-content"},s.default.createElement(n.default.Group,{className:(0,i.default)({"has-error":w&&!!w.length||!a}),id:t},j&&s.default.createElement("input",{name:f,type:"hidden",value:g.map((e=>e.value)).join()}),m&&s.default.createElement("label",{htmlFor:f+"_MultiSelect"},m,b&&s.default.createElement("span",{className:"inline-item inline-item-after reference-mark"},s.default.createElement(r.default,{symbol:"asterisk"}),s.default.createElement("span",{className:"hide-accessible sr-only"},Liferay.Language.get("required")))),s.default.createElement(n.ClayInput.Group,null,s.default.createElement(n.ClayInput.GroupItem,null,s.default.createElement(u.default,{id:f+"_MultiSelect",inputName:f,items:g,onChange:I,onItemsChange:e=>{const t=(a=e.filter((e=>!g.find((t=>t.value===e.value)))),l="label",a.map((e=>e[l])).map(((e,t,a)=>a.indexOf(e)===t&&t)).filter((e=>a[e])).map((e=>a[e])));var a,l;const n=[],r=[];t.map((e=>{k.find((t=>t.titleCurrentValue===e.label))?r.push(e):n.push(e)}));const u=g.filter((t=>!e.find((e=>e.value===t.value)))),c=[...g,...r].filter((e=>!u.find((t=>t.value===e.value))));E(n),y(c)},sourceItems:k?(0,u.itemLabelFilter)(k.map((e=>({label:e.titleCurrentValue,value:e.categoryId}))),L):[],value:L}),w&&!!w.length&&s.default.createElement(n.default.FeedbackGroup,null,s.default.createElement(n.default.FeedbackItem,{"aria-live":"polite"},s.default.createElement(n.default.FeedbackIndicator,{symbol:"info-circle"}),(0,o.sub)(Liferay.Language.get("category-x-does-not-exist"),w.map((e=>e.label)).join(",")))),!a&&s.default.createElement(n.default.FeedbackGroup,null,s.default.createElement(n.default.FeedbackItem,null,s.default.createElement(n.default.FeedbackIndicator,{symbol:"info-circle"}),s.default.createElement("span",{className:"ml-2"},Liferay.Language.get("this-field-is-required"))))),s.default.createElement(n.ClayInput.GroupItem,{shrink:!0},s.default.createElement(l.default,{displayType:"secondary",onClick:()=>{const t=(0,o.createPortletURL)(p,{selectedCategories:g.map((e=>e.value)).join(),singleSelect:v,vocabularyIds:h.concat()});(0,o.openSelectionModal)({buttonAddLabel:Liferay.Language.get("done"),height:"70vh",iframeBodyCssClass:"",multiple:!0,onSelect:e=>{if(e){const t=Object.keys(e).reduce(((t,a)=>{const l=e[a];return l.unchecked||t.push({label:l.value,value:l.categoryId}),t}),[]);y(t)}},selectEventName:e,size:"md",title:m?(0,o.sub)(Liferay.Language.get("select-x"),m):Liferay.Language.get("select-categories"),url:t.toString()})}},Liferay.Language.get("select"))))))};t.default=y}}));
//# sourceMappingURL=AssetVocabularyCategoriesSelector.es.js.map