Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.169/page_editor/app/thunks/deleteItem",["module","exports","require","frontend-js-web","../actions/deleteItem","../config/constants/freemarkerFragmentEntryProcessor","../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,I)=>{const{fragmentEntryLinks:g,layoutData:E,segmentsExperienceId:_}=I();return function markItemForDeletion({fragmentEntryLinks:e,itemId:t,layoutData:r,onNetworkStatus:n,segmentsExperienceId:o}){const i=findPortletIds(t,r,e);return u.default.markItemForDeletion({itemId:t,onNetworkStatus:n,portletIds:i,segmentsExperienceId:o}).then((e=>_objectSpread(_objectSpread({},e),{},{portletIds:i})))}({fragmentEntryLinks:g,itemId:e,layoutData:E,onNetworkStatus:r,segmentsExperienceId:_}).then((({pageContents:u,portletIds:I=[],layoutData:_})=>{t(null);const b=(0,m.default)({itemId:e,layoutData:_});r((0,o.default)({fragmentEntryLinkIds:b,itemId:e,layoutData:_,pageContents:u,portletIds:I})),function maybeShowAlert(e,t,r){var o;const u=null==e||null===(o=e.items)||void 0===o?void 0:o[t];if(!u||u.type!==a.LAYOUT_DATA_ITEM_TYPES.fragment||!(0,p.hasFormParent)(u,e))return null;const{classNameId:m,classTypeId:I}=(0,l.default)(u,e),g=(0,d.getCacheKey)([d.CACHE_KEYS.formFields,m,I]),{data:E}=(0,d.getCacheItem)(g);(E?Promise.resolve(E):c.default.getFormFields({classNameId:m,classTypeId:I})).then((e=>{if(u.type===a.LAYOUT_DATA_ITEM_TYPES.fragment&&(0,y.isRequiredFormInput)(u,r,e)){const t=(0,s.default)({fragmentEntryLinks:r},u.config.fragmentEntryLinkId,"inputFieldId",i.FREEMARKER_FRAGMENT_ENTRY_PROCESSOR),{message:o}=(0,f.getFormErrorDescription)({name:getFieldLabel(t,e),type:f.FORM_ERROR_TYPES.deletedFragment});(0,n.openToast)({message:o,type:"warning"})}}))}(E,e,g)}))}};var n=r("frontend-js-web"),o=_interopRequireDefault(r("../actions/deleteItem")),i=r("../config/constants/freemarkerFragmentEntryProcessor"),a=r("../config/constants/layoutDataItemTypes"),s=_interopRequireDefault(r("../selectors/selectEditableValue")),l=_interopRequireDefault(r("../selectors/selectFormConfiguration")),c=_interopRequireDefault(r("../services/FormService")),u=_interopRequireDefault(r("../services/LayoutService")),d=r("../utils/cache"),f=r("../utils/getFormErrorDescription"),m=_interopRequireDefault(r("../utils/getFragmentEntryLinkIdsFromItemId")),p=r("../utils/hasFormParent"),y=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