import{R as m,aP as N,l as R,o as F,a as p,j as a,bA as B,E as H,F as L,b7 as h,a9 as i,aR as k,aQ as c,y as x,aS as q,e8 as U}from"./app-BgLa5dit.js";import{C as E}from"./Cgoejc6d.chunk.js";import{D as u}from"./BrZRQuEY.chunk.js";import{D as P}from"./BE59vaMU.chunk.js";import{u as g}from"./kHNgJL0M.chunk.js";import"./KIVqng-q.chunk.js";const j="shared.publishDashboardView",t=L.encloseNamespace(j);function J(s){const[D,f]=m.useState(!1),[C,v]=m.useState(!1),d=N(),r=R(),T=F(k.currentUser()),e=g(s.dashboardToPublishId),o=g(s.dashboardToArchiveId),S=p.getDashboardTargetInfo(e.data),I=p.isContentPartnerDashboard(S);function l(){const n={...e.data,widgets:e.data.widgets.map(A=>q.omit(A,["content"]))};if(I){c(d,U.publishDashboard(s.dashboardToPublishId,()=>r.success(t("success")),()=>r.error(t("error")),s.closePopup));return}c(d,P.updateDashboard(s.dashboardToPublishId,{...n,status:x.Published},()=>r.success(t("success")),()=>r.error(t("error")),s.closePopup))}function w(){if(f(!0),!s.dashboardToArchiveId){l();return}o&&c(d,P.updateDashboard(o.data.id,{...o.data,status:x.Archived},l,()=>{r.error(t("error")),s.closePopup()}))}const b=!!T.data&&!!e.data&&(s.dashboardToArchiveId?!!o.data:!0);return a.jsx(B.Provider,{value:j,children:a.jsx(H,{title:t("title"),closePopup:s.closePopup,showLoadingSpinner:!b,children:b&&a.jsxs(a.Fragment,{children:[a.jsx("div",{children:a.jsx(h,{phrase:"heading"})}),s.dashboardToArchiveId?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mt-3",children:a.jsx(h,{phrase:"archiveHeading",options:{escapeText:!0}})}),a.jsx(u,{extraClassName:"mt-1",dashboard:o.data,theme:"danger"}),a.jsx("div",{className:"mt-3",children:a.jsx(h,{phrase:"publishHeading",options:{escapeText:!0}})}),a.jsx(u,{extraClassName:"mt-1",dashboard:e.data,theme:"success"})]}):a.jsx(u,{extraClassName:"mt-3",dashboard:e.data,theme:"success"}),a.jsx(E,{challengePhrase:e.data.name,onChallengePass:n=>v(n)}),a.jsxs(i,{className:"mt-3",children:[a.jsx(i.Cancel,{onClick:s.closePopup}),a.jsx(i.Submit,{variant:"dark",onClick:w,text:"Publish",showSpinner:D,disabled:!C})]})]})})})}export{J as PublishDashboardView};
//# sourceMappingURL=BB40mVzX.chunk.js.map
