Liferay.Loader.define("@liferay/object-web@1.0.108/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=void 0;var o=d(a("@frontend-taglib-clay$clayui/tabs")),n=a("@liferay/object-js-components-web"),i=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=u();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")),l=a("../../utils/visitor"),c=d(a("./InfoScreen/InfoScreen")),s=d(a("./LayoutScreen/LayoutScreen")),r=a("./objectLayoutContext");function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function d(e){return e&&e.__esModule?e:{default:e}}const e=Liferay.ThemeDisplay.getDefaultLanguageId(),y=[{Component:c.default,label:Liferay.Language.get("info")},{Component:s.default,label:Liferay.Language.get("layout")}],b=({objectFields:e,objectLayout:t})=>{const a=new l.TabsVisitor(t),o=e.map((({id:e})=>e)),n=[...e];return a.mapFields((e=>{const t=o.indexOf(e.objectFieldId);n[t].inLayout=!0})),n},p=({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},j=()=>{const[{isViewOnly:t,objectFields:a,objectLayout:l,objectLayoutId:c},s]=(0,r.useLayoutContext)(),[u,d]=(0,i.useState)(0),[f,j]=(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(c)),i=await n.API.getObjectDefinition(a),l=await n.API.getObjectFields(a),u=await n.API.getObjectRelationships(a),d={defaultObjectLayout:e,name:t,objectDefinitionId:a,objectLayoutTabs:o};s({payload:{objectLayout:d},type:r.TYPES.ADD_OBJECT_LAYOUT});const f=l.filter((({system:e})=>!e));s({payload:{objectDefinition:i},type:r.TYPES.ADD_OBJECT_DEFINITION}),s({payload:{objectFields:b({objectFields:f,objectLayout:d})},type:r.TYPES.ADD_OBJECT_FIELDS}),s({payload:{objectRelationships:p({objectLayoutTabs:o,objectRelationships:u})},type:r.TYPES.ADD_OBJECT_RELATIONSHIPS}),j(!1)})()}),[c,s]),i.default.createElement(n.SidePanelContent,{onSave:async()=>{const t=a.some((e=>e.inLayout));if((0,n.invalidateRequired)(l.name[e]))(0,n.openToast)({message:Liferay.Language.get("a-name-is-required"),type:"danger"});else if(t)if(l.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(c),l),(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||f,title:Liferay.Language.get("layout")},i.default.createElement(o.default,{className:"side-panel-iframe__tabs"},y.map((({label:e},t)=>i.default.createElement(o.default.Item,{active:u===t,key:t,onClick:()=>d(t)},e)))),i.default.createElement(o.default.Content,{activeIndex:u,fade:!0},y.map((({Component:e},t)=>i.default.createElement(o.default.TabPane,{key:t},!f&&i.default.createElement(e,null))))))};var f=({isViewOnly:e,objectFieldTypes:t,objectLayoutId:a})=>i.default.createElement(r.LayoutContextProvider,{value:{isViewOnly:e,objectFieldTypes:t,objectLayoutId:a}},i.default.createElement(j,null));t.default=f}}));
//# sourceMappingURL=index.js.map