"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2859],{50749(U,f,s){s.d(f,{EmbeddedDashboard:()=>h});var t=s(14553),l=s(22803),_=s(55501),u=s(91715),D=s(52358),i=s(36736),P=s(46633),M=s(33100),O=s(91660),g=s(49439),v=s(25948),m=s(82311),A=s(46333),T=s(74352);function h(a){const r=(0,A.sP)(),{dashboard:e,loadError:n}=r.useState();return(0,T.kt)(),(0,_.useEffect)(()=>(r.loadDashboard({uid:a.uid,route:m.Z4.Embedded}),()=>{r.clearState()}),[r,a.uid]),n?(0,t.jsx)(M.F,{severity:"error",title:(0,D.t)("dashboard.errors.failed-to-load","Failed to load dashboard"),children:(0,v.q6)(n)}):e?(0,t.jsx)(x,{model:e,...a}):(0,t.jsx)(O.y,{})}function x({model:a,initialState:r,onStateChange:e}){const[n,E]=(0,_.useState)(!1),{controls:o,body:d}=a.useState(),c=(0,g.of)(b);return(0,_.useEffect)(()=>{if(E(!0),r){const R=new URLSearchParams(r);i.Go.syncStateFromSearchParams(a,R)}return a.activate()},[a]),C(e,a),n?(0,t.jsxs)("div",{className:(0,l.cx)(c.canvas,o&&c.canvasWithControls),children:[o&&(0,t.jsx)("div",{className:c.controlsWrapper,children:(0,t.jsx)(o.Component,{model:o})}),(0,t.jsx)("div",{className:c.body,children:(0,t.jsx)(d.Component,{model:d})})]}):null}function C(a,r){(0,_.useEffect)(()=>{if(!a)return;let e="";const n=r.subscribeToEvent(P.b,E=>{if(E.payload.changedObject.urlSync){const o=i.Go.getUrlState(r),d=u.kM.renderUrl("",o);e!==d&&(e=d,a(d))}});return()=>n.unsubscribe()},[r,a])}function b(a){return{canvas:(0,l.css)({label:"canvas-content",display:"grid",gridTemplateAreas:`
        "panels"`,gridTemplateColumns:"1fr",gridTemplateRows:"1fr",flexBasis:"100%",flexGrow:1}),canvasWithControls:(0,l.css)({gridTemplateAreas:`
        "controls"
        "panels"`,gridTemplateRows:"auto 1fr"}),body:(0,l.css)({label:"body",flexGrow:1,display:"flex",flexDirection:"column",gap:"8px",gridArea:"panels",marginBottom:a.spacing(2)}),controlsWrapper:(0,l.css)({display:"flex",flexDirection:"column",flexGrow:0,gridArea:"controls",padding:a.spacing(2,0,2,2)})}}}}]);

//# sourceMappingURL=EmbeddedDashboard-react19.c397fe5f18dad17e75d9.js.map