Liferay.Loader.define("@liferay/object-web@1.0.181/js/components/Layout/index",["module","exports","require","@frontend-taglib-clay$clayui/tabs","@liferay/object-js-components-web","liferay!frontend-js-react-web$react","../../utils/constants","../../utils/visitor","./InfoScreen/InfoScreen","./LayoutScreen/LayoutScreen","./objectLayoutContext"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function LayoutWrapper({isViewOnly:e,objectFieldTypes:t,objectLayoutId:a}){return i.default.createElement(s.LayoutContextProvider,{value:{isViewOnly:e,objectFieldTypes:t,objectLayoutId:a}},i.default.createElement(Layout,null))};var n=_interopRequireDefault(a("@frontend-taglib-clay$clayui/tabs")),o=a("@liferay/object-js-components-web"),i=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 a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var i=n?Object.getOwnPropertyDescriptor(e,o):null;i&&(i.get||i.set)?Object.defineProperty(a,o,i):a[o]=e[o]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react")),r=a("../../utils/constants"),c=a("../../utils/visitor"),l=_interopRequireDefault(a("./InfoScreen/InfoScreen")),u=_interopRequireDefault(a("./LayoutScreen/LayoutScreen")),s=a("./objectLayoutContext");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 e=[{Component:l.default,label:Liferay.Language.get("info")},{Component:u.default,label:Liferay.Language.get("layout")}],normalizeObjectFields=({objectFields:e,objectLayout:t})=>{const a=new c.TabsVisitor(t),n=e.map((({name:e})=>e)),o=[...e];return a.mapFields((e=>{const t=n.indexOf(e.objectFieldName);o[t].inLayout=!0})),o},normalizeObjectRelationships=({objectLayoutTabs:e,objectRelationships:t})=>{const a=t.map((({id:e})=>e)),n=[...t];return e.forEach((({objectRelationshipId:e})=>{if(e){const t=a.indexOf(e);n[t].inLayout=!0}})),n},Layout=()=>{const[{isViewOnly:t,objectFields:a,objectLayout:c,objectLayoutId:l},u]=(0,s.useLayoutContext)(),[d,f]=(0,i.useState)(0),[y,b]=(0,i.useState)(!0);return(0,i.useEffect)((()=>{(async()=>{const{defaultObjectLayout:e,name:t,objectDefinitionExternalReferenceCode:a,objectLayoutTabs:n}=await o.API.fetchJSON("/o/object-admin/v1.0/object-layouts/".concat(l)),i=await o.API.getObjectDefinitionByExternalReferenceCode(a),r=await o.API.getObjectFieldsByExternalReferenceCode(a),c=await o.API.getObjectRelationshipsByExternalReferenceCode(a),d={defaultObjectLayout:e,name:t,objectDefinitionExternalReferenceCode:a,objectLayoutTabs:n};u({payload:{creationLanguageId:i.defaultLanguageId,enableCategorization:i.enableCategorization,objectLayout:d,objectRelationships:normalizeObjectRelationships({objectLayoutTabs:n,objectRelationships:c})},type:s.TYPES.ADD_OBJECT_LAYOUT});const f=r.filter((({system:e})=>!e));u({payload:{objectFields:normalizeObjectFields({objectFields:f,objectLayout:d})},type:s.TYPES.ADD_OBJECT_FIELDS}),b(!1)})()}),[l,u]),i.default.createElement(o.SidePanelContent,{onSave:async()=>{const e=a.some((e=>e.inLayout));if((0,o.invalidateRequired)(c.name[r.defaultLanguageId]))(0,o.openToast)({message:Liferay.Language.get("a-name-is-required"),type:"danger"});else if(e)if(c.objectLayoutTabs[0].objectRelationshipId>0)(0,o.openToast)({message:Liferay.Language.get("the-layouts-first-tab-must-be-a-field-tab"),type:"danger"});else try{await o.API.save("/o/object-admin/v1.0/object-layouts/".concat(l),c),(0,o.saveAndReload)(),(0,o.openToast)({message:Liferay.Language.get("the-object-layout-was-updated-successfully")})}catch(e){const{message:t}=e;(0,o.openToast)({message:t,type:"danger"})}else(0,o.openToast)({message:Liferay.Language.get("please-add-at-least-one-field"),type:"danger"})},readOnly:t||y,title:Liferay.Language.get("layout")},i.default.createElement(n.default,{className:"side-panel-iframe__tabs"},e.map((({label:e},t)=>i.default.createElement(n.default.Item,{active:d===t,key:t,onClick:()=>f(t)},e)))),i.default.createElement(n.default.Content,{activeIndex:d,fade:!0},e.map((({Component:e},t)=>i.default.createElement(n.default.TabPane,{key:t},!y&&i.default.createElement(e,null))))))}}}));
//# sourceMappingURL=index.js.map