Liferay.Loader.define("@liferay/object-web@1.0.145/js/components/EditObjectStateField",["module","exports","require","@liferay/object-js-components-web","frontend-js-web","liferay!frontend-js-react-web$react","./ObjectField/useObjectFieldForm","./StateManager/StateDefinition"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function EditObjectStateField({objectField:e,readOnly:t}){const[r,l]=(0,a.useState)([]);(0,a.useEffect)((()=>{(null==e?void 0:e.listTypeDefinitionId)&&n.API.getPickListItems(e.listTypeDefinitionId).then(l)}),[e.listTypeDefinitionId,l]);const isStateOptionChecked=({currentKey:t,pickListItemKey:r})=>void 0!==e.objectFieldSettings.find((({name:e})=>"stateFlow"===e)).value.objectStates.find((e=>e.key===t)).objectStateTransitions.find((({key:e})=>e===r)),{handleSubmit:s,setValues:u,values:f}=(0,o.useObjectFieldForm)({initialValues:e,onSubmit:async e=>{let{id:t}=e,r=function _objectWithoutProperties(e,t){if(null==e)return{};var r,n,i=function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}(e,["id"]);delete r.listTypeDefinitionId,delete r.system;try{await n.API.save("/o/object-admin/v1.0/object-fields/".concat(t),r),(0,n.saveAndReload)(),(0,i.openToast)({message:Liferay.Language.get("the-object-field-was-updated-successfully")})}catch(e){(0,i.openToast)({message:e.message,type:"danger"})}}});return a.default.createElement(n.SidePanelForm,{className:"lfr-objects__edit-object-state-field",onSubmit:s,readOnly:t,title:"".concat(e.label[Liferay.ThemeDisplay.getDefaultLanguageId()]," ").concat(Liferay.Language.get("settings"))},a.default.createElement(n.Card,{title:Liferay.Language.get("select-the-state-flow")},null==r?void 0:r.map((({key:e,name:n},i)=>a.default.createElement(c.default,{currentKey:e,disabled:t,index:i,initialValues:r.filter((e=>e.name!==n)).map((t=>_objectSpread(_objectSpread({},t),{},{checked:isStateOptionChecked({currentKey:e,pickListItemKey:t.key})}))),key:i,setValues:u,stateName:n,values:f})))))};var n=r("@liferay/object-js-components-web"),i=r("frontend-js-web"),a=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={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var a=n?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(r,i,a):r[i]=e[i]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),o=r("./ObjectField/useObjectFieldForm"),c=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(r("./StateManager/StateDefinition"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},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}}}));
//# sourceMappingURL=EditObjectStateField.js.map