Liferay.Loader.define("asset-list-web@3.0.88/js/components/VariationsNav/SortableList",["module","exports","require","@frontend-taglib-clay$clayui/list","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","liferay!frontend-js-react-web$react-dnd","liferay!frontend-js-react-web$react-dnd-html5-backend","../../api/index","./SortableListItem","./utils/index"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=_interopRequireDefault(r("@frontend-taglib-clay$clayui/list")),n=r("frontend-js-web"),i=(_interopRequireDefault(r("liferay!frontend-js-react-web$prop-types")),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 r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=a?Object.getOwnPropertyDescriptor(e,n):null;i&&(i.get||i.set)?Object.defineProperty(r,n,i):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),o=r("liferay!frontend-js-react-web$react-dnd"),l=r("liferay!frontend-js-react-web$react-dnd-html5-backend"),s=r("../../api/index"),d=_interopRequireDefault(r("./SortableListItem")),c=r("./utils/index");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const savePriority=async({itemIndex:e,itemName:t,url:r})=>{try{const{ok:a,status:i}=await(0,s.saveVariationsListPriorityService)({url:r});if(!a||200!==i)throw new Error;(0,n.openToast)({message:(0,n.sub)(Liferay.Language.get("variation-x-moved-to-position-x"),t,e+1),type:"success"})}catch(e){(0,n.openToast)({message:Liferay.Language.get("an-unexpected-error-occurred"),type:"danger"})}};var _default=({items:e,namespace:t,savePriorityURL:r})=>{const[s,u]=(0,i.useState)(e),handleItemMove=({direction:e=0,hoverIndex:t=null,index:r,saveAfterMove:a=!1})=>{const n=null!=t?t:r+e,i=[...s];i.splice(r,1),i.splice(n,0,s[r]),u(i),a&&handleSavePriority({itemIndex:n,itemName:s[r].name,items:i})},handleSavePriority=({itemIndex:e,itemName:a,items:n=s})=>{savePriority({itemIndex:e,itemName:a,url:(0,c.buildItemsPriorityURL)({items:n,namespace:t,url:r})})},handleItemDelete=({deleteURL:e})=>{e&&(0,n.openConfirmModal)({message:Liferay.Language.get("are-you-sure-you-want-to-delete-this"),onConfirm:t=>{t&&submitForm(document.hrefFm,e)}})};return i.default.createElement(o.DndProvider,{backend:l.HTML5Backend},i.default.createElement("nav",{role:"navigation"},i.default.createElement(a.default,{className:"mt-4",role:"list"},s.map(((e,t)=>i.default.createElement(d.default,{handleItemDelete:handleItemDelete,handleItemMove:handleItemMove,handleSavePriority:handleSavePriority,id:"sortableListItem-id-".concat(e.assetListEntrySegmentsEntryRelId),index:t,key:e.editAssetListEntryURL,role:"listitem",sortableListItem:e,totalItems:s.length}))))))};t.default=_default}}));
//# sourceMappingURL=SortableList.js.map