Liferay.Loader.define("data-engine-js-components-web@1.0.79/js/core/hooks/useDrop.es",["module","exports","require","liferay!frontend-js-react-web$react-dnd","../../utils/dataConverter","../../utils/dragTypes","../actions/eventTypes.es","../thunks/elementSetAdded.es","./useConfig.es","./useForm.es"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useDrop=function({columnIndex:t,field:n,origin:u,pageIndex:c,parentField:f,rowIndex:m}){const{editingLanguageId:g}=(0,s.useFormState)(),{fieldTypes:b}=(0,o.useConfig)(),P=(0,s.useForm)(),T={columnIndex:t,pageIndex:c,rowIndex:m},{DRAG_DATA_DEFINITION_FIELD_ADD:O,DRAG_FIELD_TYPE_ADD:x,DRAG_FIELD_TYPE_MOVE:_,DRAG_FIELDSET_ADD:j}=a,[{canDrop:w,overTarget:S},h]=(0,r.useDrop)({accept:[...Object.values(a),D],canDrop:e=>!(F(n,e.data)||I(n,e.data)||N(e.data,n)||y({sourceIndexes:e.sourceIndexes,sourceParentField:e.sourceParentField,targetIndexes:{columnIndex:t,pageIndex:c,rowIndex:m},targetParentField:f,type:e.data.type})),collect:e=>({canDrop:e.canDrop(),overTarget:e.isOver({shallow:!0})}),drop:({data:t,sourceIndexes:r,sourceParentField:a,type:o},s)=>{if(!s.didDrop()&&s.canDrop()&&!v(u,f)&&!E(u,a,f))switch(o){case x:P({payload:{data:{fieldName:null==n?void 0:n.fieldName,parentFieldName:null==f?void 0:f.fieldName},fieldType:p(p({},b.find((({name:e})=>e===t.name))),{},{editable:!0}),indexes:T},type:u===e.EMPTY?i.EVENT_TYPES.FIELD.ADD:i.EVENT_TYPES.SECTION.ADD});break;case _:P({payload:{sourceFieldName:t.fieldName,sourceFieldPage:r.pageIndex,sourceParentField:a,targetFieldName:null==n?void 0:n.fieldName,targetIndexes:T,targetParentFieldName:null==f?void 0:f.fieldName},type:i.EVENT_TYPES.DND.MOVE});break;case O:{const{dataDefinition:r,name:a}=t,l=r.dataDefinitionFields.find((e=>e.name===a)),o=(0,d.getDDMFormFieldSettingsContext)({dataDefinitionField:l,editingLanguageId:g,fieldTypes:b}),{fieldType:s,label:c}=l;P({payload:{data:{fieldName:null==n?void 0:n.fieldName,parentFieldName:null==f?void 0:f.fieldName},fieldType:p(p({},b.find((({name:e})=>e===s))),{},{editable:!0,label:c[null!=g?g:themeDisplay.getLanguageId()],settingsContext:o}),indexes:T,skipFieldNameGeneration:!0},type:u===e.EMPTY?i.EVENT_TYPES.FIELD.ADD:i.EVENT_TYPES.SECTION.ADD});break}case j:{const{fieldSet:e,properties:r,useFieldName:d}=t;P({payload:{fieldName:null==n?void 0:n.fieldName,fieldSet:e,indexes:T,parentFieldName:null==f?void 0:f.fieldName,properties:r,useFieldName:d},type:i.EVENT_TYPES.FIELD_SET.ADD});break}case D:P((0,l.elementSetAdded)(p({indexes:T},t.payload)))}}});return{canDrop:w,drop:h,overTarget:S}},t.DND_ORIGIN_TYPE=void 0;var r=n("liferay!frontend-js-react-web$react-dnd"),d=n("../../utils/dataConverter"),a=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=u();if(t&&t.has(e))return t.get(e);var n={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var d in e)if(Object.prototype.hasOwnProperty.call(e,d)){var a=r?Object.getOwnPropertyDescriptor(e,d):null;a&&(a.get||a.set)?Object.defineProperty(n,d,a):n[d]=e[d]}n.default=e,t&&t.set(e,n);return n}(n("../../utils/dragTypes")),i=n("../actions/eventTypes.es"),l=n("../thunks/elementSetAdded.es"),o=n("./useConfig.es"),s=n("./useForm.es");function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const e={EMPTY:"empty",FIELD:"field"};t.DND_ORIGIN_TYPE=e;const D="elementSet:add",m=(e,t)=>e.pageIndex===t.pageIndex&&e.rowIndex===t.rowIndex&&e.columnIndex===t.columnIndex,g=(e,t)=>!e.slice(-t.length).some(((e,n)=>!m(e,t[n])))&&e.length>t.length,y=({sourceIndexes:e,sourceParentField:t,targetIndexes:n,targetParentField:r,type:d})=>{var a,i;return"fieldset"===d&&g([n,...null!==(a=null==r?void 0:r.loc)&&void 0!==a?a:[]],[e,...null!==(i=null==t?void 0:t.loc)&&void 0!==i?i:[]])},I=(e,t)=>"fieldset"===(null==t?void 0:t.type)&&void 0!==e,v=(t,n)=>t===e.FIELD&&"fieldset"===(null==n?void 0:n.type)&&1===n.nestedFields.length,E=(t,n,r)=>t===e.FIELD&&"fieldset"===(null==n?void 0:n.type)&&(null==n?void 0:n.fieldName)===(null==r?void 0:r.fieldName)&&2===r.nestedFields.length,N=(e,t)=>e.fieldName!==(null==t?void 0:t.fieldName)&&"fieldset"===(null==t?void 0:t.type)&&!!(null==t?void 0:t.ddmStructureId),F=(e,t)=>e&&e.fieldName===t.fieldName}}));
//# sourceMappingURL=useDrop.es.js.map