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