Liferay.Loader.define("@liferay/analytics-settings-web@5.0.47/js/components/properties/Properties",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/modal","liferay!frontend-js-react-web$react","../../utils/api","../../utils/constants","../../utils/useRequest","../StateRenderer","./AssignModal","./CreatePropertyModal","./PropertiesTable"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=_interopRequireDefault(r("@frontend-taglib-clay$clayui/button")),n=r("@frontend-taglib-clay$clayui/modal"),l=_interopRequireWildcard(r("liferay!frontend-js-react-web$react")),o=r("../../utils/api"),i=r("../../utils/constants"),u=r("../../utils/useRequest"),c=_interopRequireWildcard(r("../StateRenderer")),d=_interopRequireDefault(r("./AssignModal")),s=_interopRequireDefault(r("./CreatePropertyModal")),f=_interopRequireDefault(r("./PropertiesTable"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}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={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var l=a?Object.getOwnPropertyDescriptor(e,n):null;l&&(l.get||l.set)?Object.defineProperty(r,n,l):r[n]=e[n]}return r.default=e,t&&t.set(e,r),r}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var _default=()=>{const[e,t]=(0,l.useState)([]),{observer:r,onOpenChange:p,open:y}=(0,n.useModal)(),{observer:m,onOpenChange:g,open:b}=(0,n.useModal)(),[E,_]=(0,l.useState)(e[0]),{data:h,error:C,loading:S,refetch:R}=(0,u.useRequest)(o.fetchProperties);(0,l.useEffect)((()=>{(null==h?void 0:h.items)&&t(h.items)}),[h]);const handleCloseModal=async e=>{const{items:r}=await(0,o.fetchProperties)();t(r),Liferay.Util.openToast({message:i.SUCCESS_MESSAGE}),e(!1)};return l.default.createElement(l.default.Fragment,null,l.default.createElement(c.default,{empty:!e.length,error:C,loading:S},l.default.createElement(c.default.Error,null,l.default.createElement(c.ErrorStateComponent,{className:"empty-state-border mb-0 pb-5",onClickRefetch:R})),l.default.createElement(c.default.Empty,null,l.default.createElement(c.EmptyStateComponent,{className:"empty-state-border",description:Liferay.Language.get("create-a-property-to-add-sites-and-channels"),imgSrc:i.NOT_FOUND_GIF,title:Liferay.Language.get("create-a-new-property")},l.default.createElement(a.default,{displayType:"secondary",onClick:()=>g(!0),type:"button"},Liferay.Language.get("new-property")))),l.default.createElement(c.default.Success,null,l.default.createElement("div",{className:"text-right"},l.default.createElement(a.default,{displayType:"secondary",onClick:()=>g(!0),type:"button"},Liferay.Language.get("new-property"))),l.default.createElement(f.default,{onAssign:t=>{_(e[t]),p(!0)},onCommerceSwitchChange:async r=>{const a=[...e],{channelId:n,commerceSyncEnabled:l}=a[r],{ok:i}=await(0,o.updateProperty)({channelId:n,commerceSyncEnabled:!l});i&&(a[r].commerceSyncEnabled=!l,t(a))},properties:e}))),y&&l.default.createElement(d.default,{observer:r,onCancel:()=>p(!1),onSubmit:()=>handleCloseModal(p),property:E}),b&&l.default.createElement(s.default,{observer:m,onCancel:()=>g(!1),onSubmit:()=>handleCloseModal(g)}))};t.default=_default}}));
//# sourceMappingURL=Properties.js.map