Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.173/page_editor/app/thunks/deleteItem",["module","exports","require","frontend-js-web","../actions/deleteItem","../config/constants/freemarkerFragmentEntryProcessor","../config/constants/itemActivationOrigins","../config/constants/layoutDataItemTypes","../selectors/selectEditableValue","../selectors/selectFormConfiguration","../services/FormService","../services/LayoutService","../utils/cache","../utils/getFormErrorDescription","../utils/getFragmentEntryLinkIdsFromItemId","../utils/hasFormParent","../utils/isRequiredFormInput"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function deleteItem({itemId:e,selectItem:t=(()=>{})}){return(r,y)=>{const{fragmentEntryLinks:E,layoutData:_,segmentsExperienceId:b}=y();return function markItemForDeletion({fragmentEntryLinks:e,itemId:t,layoutData:r,onNetworkStatus:n,segmentsExperienceId:o}){const i=findPortletIds(t,r,e);return d.default.markItemForDeletion({itemId:t,onNetworkStatus:n,portletIds:i,segmentsExperienceId:o}).then((e=>_objectSpread(_objectSpread({},e),{},{portletIds:i})))}({fragmentEntryLinks:E,itemId:e,layoutData:_,onNetworkStatus:r,segmentsExperienceId:b}).then((({pageContents:d,portletIds:y=[],layoutData:b})=>{const[F]=b.items[b.rootItems.main].children;t(F,{origin:s.ITEM_ACTIVATION_ORIGINS.itemActions});const O=(0,p.default)({itemId:e,layoutData:b});r((0,o.default)({fragmentEntryLinkIds:O,itemId:e,layoutData:b,pageContents:d,portletIds:y})),function maybeShowAlert(e,t,r){var o;const s=null==e||null===(o=e.items)||void 0===o?void 0:o[t];if(!s||s.type!==a.LAYOUT_DATA_ITEM_TYPES.fragment||!(0,I.hasFormParent)(s,e))return null;const{classNameId:d,classTypeId:p}=(0,l.default)(s,e),y=(0,f.getCacheKey)([f.CACHE_KEYS.formFields,d,p]),{data:E}=(0,f.getCacheItem)(y);(E?Promise.resolve(E):u.default.getFormFields({classNameId:d,classTypeId:p})).then((e=>{if(s.type===a.LAYOUT_DATA_ITEM_TYPES.fragment&&(0,g.isRequiredFormInput)(s,r,e)){const t=(0,c.default)({fragmentEntryLinks:r},s.config.fragmentEntryLinkId,"inputFieldId",i.FREEMARKER_FRAGMENT_ENTRY_PROCESSOR),{message:o}=(0,m.getFormErrorDescription)({name:getFieldLabel(t,e),type:m.FORM_ERROR_TYPES.deletedFragment});(0,n.openToast)({message:o,type:"warning"})}}))}(_,e,E)}))}};var n=r("frontend-js-web"),o=_interopRequireDefault(r("../actions/deleteItem")),i=r("../config/constants/freemarkerFragmentEntryProcessor"),s=r("../config/constants/itemActivationOrigins"),a=r("../config/constants/layoutDataItemTypes"),c=_interopRequireDefault(r("../selectors/selectEditableValue")),l=_interopRequireDefault(r("../selectors/selectFormConfiguration")),u=_interopRequireDefault(r("../services/FormService")),d=_interopRequireDefault(r("../services/LayoutService")),f=r("../utils/cache"),m=r("../utils/getFormErrorDescription"),p=_interopRequireDefault(r("../utils/getFragmentEntryLinkIdsFromItemId")),I=r("../utils/hasFormParent"),g=r("../utils/isRequiredFormInput");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function findPortletIds(e,t,r){const n=t.items[e],{config:o={},children:i=[]}=n;if(n.type===a.LAYOUT_DATA_ITEM_TYPES.fragment&&o.fragmentEntryLinkId){const{editableValues:e={}}=r[o.fragmentEntryLinkId];if(e.portletId)return[e.instanceId?"".concat(e.portletId,"_INSTANCE_").concat(e.instanceId):e.portletId]}const s=[];return i.forEach((e=>{s.push(...findPortletIds(e,t,r))})),s}function getFieldLabel(e,t){return t.flatMap((e=>e.fields)).find((t=>t.key===e)).label}}}));
//# sourceMappingURL=deleteItem.js.map