Liferay.Loader.define("asset-taglib@8.0.17/asset_tags_selector/AssetTagsSelector.es",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/data-provider","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/multi-select","@liferay/frontend-js-react-web","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=s(a("@frontend-taglib-clay$clayui/button")),n=a("@frontend-taglib-clay$clayui/data-provider"),r=d(a("@frontend-taglib-clay$clayui/form")),o=d(a("@frontend-taglib-clay$clayui/multi-select")),u=a("@liferay/frontend-js-react-web"),c=a("frontend-js-web"),i=(s(a("liferay!frontend-js-react-web$prop-types")),d(a("liferay!frontend-js-react-web$react")));function f(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return f=function(){return e},e}function d(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=f();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 s(e){return e&&e.__esModule?e:{default:e}}const e=()=>{};var p=function({addCallback:t,groupIds:a=[],id:f,inputName:d,inputValue:s,label:p,onInputValueChange:y=e,onSelectedItemsChange:g=e,portletURL:b,removeCallback:m,selectedItems:v=[],showSelectButton:h}){const{refetch:w,resource:j}=(0,n.useResource)({fetchOptions:{body:(0,c.objectToFormData)({cmd:JSON.stringify({"/assettag/search":{end:20,groupIds:a,name:"%".concat("*"===s?"":s,"%"),start:0,tagProperties:""}}),p_auth:Liferay.authToken}),credentials:"include",method:"POST","x-csrf-token":Liferay.authToken},link:"".concat(window.location.origin).concat(themeDisplay.getPathContext(),"\n\t\t\t\t/api/jsonws/invoke")}),L=(0,u.usePrevious)(s);(0,i.useEffect)((()=>{s&&s!==L&&w()}),[s,L,w]);const I=(e,t)=>{e&&"function"==typeof window[e]&&window[e](t)};return i.default.createElement("div",{className:"lfr-tags-selector-content",id:f},i.default.createElement(r.default.Group,null,i.default.createElement("label",{htmlFor:d+"_MultiSelect"},p||Liferay.Language.get("tags")),i.default.createElement(r.ClayInput.Group,null,i.default.createElement(r.ClayInput.GroupItem,null,i.default.createElement(o.default,{id:d+"_MultiSelect",inputName:d,items:v,onBlur:()=>{const e=j&&j.map((e=>e.value));e&&e.length||s&&(v.find((e=>e.label===s))||g(v.concat({label:s,value:s})),y(""))},onChange:y,onItemsChange:e=>{const a=e.filter((e=>!v.find((t=>t.value===e.value)))),l=v.filter((t=>!e.find((e=>e.value===t.value)))),n=[...v,...a].filter((e=>!l.find((t=>t.value===e.value))));g(n),a.forEach((e=>I(t,e))),l.forEach((e=>I(m,e)))},sourceItems:j?(0,o.itemLabelFilter)(j.map((e=>({label:e.text,value:e.value}))),s):[],value:s})),h&&i.default.createElement(r.ClayInput.GroupItem,{shrink:!0},i.default.createElement(l.default,{displayType:"secondary",onClick:()=>{const e=(a=decodeURIComponent(b),l={selectedTagNames:v.map((e=>e.value)).join()},a.replace(/\{([^}]+)\}/g,((e,t)=>l[t])));var a,l;(0,c.openSelectionModal)({buttonAddLabel:Liferay.Language.get("done"),getSelectedItemsOnly:!1,multiple:!0,onSelect:e=>{if(!(null==e?void 0:e.length))return;let[a,l]=e.reduce((([e,t],a)=>a.checked?[[...e,{label:a.value,value:a.value}],t]:[e,[...t,{label:a.value,value:a.value}]]),[[],[]]);a=a.filter((e=>!v.find((t=>t.label===e.label)))),l=v.filter((e=>l.find((t=>t.label===e.label))));const n=v.concat(a).filter((e=>!l.includes(e)));g(n),a.forEach((e=>I(t,e))),l.forEach((e=>I(m,e)))},title:Liferay.Language.get("tags"),url:e})}},Liferay.Language.get("select"))))))};t.default=p}}));
//# sourceMappingURL=AssetTagsSelector.es.js.map