Liferay.Loader.define("@liferay/document-library-web@6.0.111/document_library/js/categorization/tags/EditTagsModal.es",["module","exports","require","@frontend-taglib-clay$clayui/alert","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/loading-indicator","@frontend-taglib-clay$clayui/modal","@liferay/frontend-js-react-web","asset-taglib","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","./EditTagsContext.es"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=g(a("@frontend-taglib-clay$clayui/alert")),n=g(a("@frontend-taglib-clay$clayui/button")),r=a("@frontend-taglib-clay$clayui/form"),o=g(a("@frontend-taglib-clay$clayui/loading-indicator")),d=g(a("@frontend-taglib-clay$clayui/modal")),u=a("@liferay/frontend-js-react-web"),i=a("asset-taglib"),c=a("frontend-js-web"),s=(g(a("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=y();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]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"))),f=g(a("./EditTagsContext.es"));function y(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return y=function(){return e},e}function g(e){return e&&e.__esModule?e:{default:e}}const e="/bulk/v1.0/bulk-selection",m="/bulk/v1.0/keywords/common",b="/bulk/v1.0/keywords/batch",v=()=>{};var p=({fileEntries:t,folderId:a,groupIds:y,pathModule:g,repositoryId:p,selectAll:h=!1,observer:L,onModalClose:E=v})=>{const{namespace:w}=(0,s.useContext)(f.default),j=(0,u.useIsMounted)(),[S,I]=(0,s.useState)(!0),[k,C]=(0,s.useState)(""),[$,T]=(0,s.useState)(!0),[O,P]=(0,s.useState)(!1),[M,x]=(0,s.useState)([]),[_,A]=(0,s.useState)(""),[N,R]=(0,s.useState)([]),[z,B]=(0,s.useState)("add"),D=t&&t.length,W=(0,s.useCallback)(((e,t,a)=>{const l={body:JSON.stringify(a),headers:{"Content-Type":"application/json"},method:t};return(0,c.fetch)("".concat(g).concat(e),l).then((e=>204===e.status?"":e.json())).catch((()=>{E()}))}),[E,g]);return(0,s.useEffect)((()=>{const l={documentIds:t,selectionScope:{folderId:a,repositoryId:p,selectAll:h}};Promise.all([W(m,"POST",l),W(e,"POST",l)]).then((([e,a])=>{if(e&&a){const n=(e.items||[]).map((({name:e})=>({label:e,value:e})));j()&&(T(!1),x(n),R(n),C(1===(l=a.size)?Liferay.Language.get("you-are-editing-the-tags-for-the-selected-item"):(0,c.sub)(Liferay.Language.get("you-are-editing-the-common-tags-for-x-items.-select-edit-or-replace-current-tags"),l)),P(t.length>1||h))}var l}))}),[W,t,D,a,j,p,h]),s.default.createElement(d.default,{observer:L,size:"md"},s.default.createElement(d.default.Header,null,Liferay.Language.get("edit-tags")),s.default.createElement("form",{onSubmit:e=>{e.preventDefault();const l=S?N.filter((e=>!M.find((t=>t.value===e.value)))):N,n=M.filter((e=>!N.find((t=>t.value===e.value))));W(b,S?"PATCH":"PUT",{documentBulkSelection:{documentIds:t,selectionScope:{folderId:a,repositoryId:p,selectAll:h}},keywordsToAdd:l.map((e=>e.value)),keywordsToRemove:n.map((e=>e.value))}).then((()=>{const e=Liferay.component("".concat(w,"BulkStatus"));e&&e.startWatch(),E()}))}},s.default.createElement(d.default.Body,null,$&&s.default.createElement(o.default,null),h&&s.default.createElement(l.default,{title:""},Liferay.Language.get("this-operation-will-not-be-applied-to-any-of-the-selected-folders")),s.default.createElement("p",null,k),O&&s.default.createElement(r.ClayRadioGroup,{name:"add-replace",onChange:e=>{I("add"===e),B(e)},value:z},s.default.createElement(r.ClayRadio,{label:Liferay.Language.get("edit"),value:"add"},s.default.createElement("div",{className:"form-text"},Liferay.Language.get("add-new-tags-or-remove-common-tags"))),s.default.createElement(r.ClayRadio,{label:Liferay.Language.get("replace"),value:"replace"},s.default.createElement("div",{className:"form-text"},Liferay.Language.get("these-tags-replace-all-existing-tags")))),s.default.createElement(i.AssetTagsSelector,{groupIds:y,inputName:"".concat(w,"_hiddenInput"),inputValue:_,onInputValueChange:A,onSelectedItemsChange:R,selectedItems:N})),s.default.createElement(d.default.Footer,{last:s.default.createElement(n.default.Group,{spaced:!0},s.default.createElement(n.default,{displayType:"secondary",onClick:E},Liferay.Language.get("cancel")),s.default.createElement(n.default,{displayType:"primary",type:"submit"},Liferay.Language.get("save")))})))};t.default=p}}));
//# sourceMappingURL=EditTagsModal.es.js.map