"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const I=require("react/jsx-runtime"),j=require("react"),P=require("../data/DataProvider.js"),_=require("../data/DataConsumer.js"),U=require("react-redux"),E=require("../chart/Tooltip.js"),L=u=>{const{editing:l=!1,unique:p,intl:r,childContent:s,"data-csv":h="","data-dvz-proxy-dataset-id":f,"data-view-mode":z="info","data-app":y,"data-measures":b="{}","data-format":v="{}","data-group":m,"data-filters":x="[]","data-number-font-size":a=20,"data-number-color":V="#000000","data-wait-for-filters":M="false","data-no-data-text":q="-","data-text-template":C=""}=u,R=r.locale,H=j.useRef(null);let w=!1,F="";try{const t=new URLSearchParams(window.location.search);w=t.get("autoHeight")==="1"||t.get("autoHeight")==="true",F=t.get("frameId")||""}catch{}const g=t=>l?t:decodeURIComponent(t),o=t=>{try{return JSON.parse(g(t))}catch{console.error("error parsing value:"+t)}return null},d=o(v),i=d?{style:d.style==="compacted"?"decimal":d.style,notation:d.style==="compacted"?"compact":"standard",currency:d.currency,minimumFractionDigits:parseInt(d.minimumFractionDigits),maximumFractionDigits:parseInt(d.maximumFractionDigits)}:{notation:"standard",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2},[N,T]=j.useState(z),S=Math.max(24,(a||14)*1.2),D={},c=o(x)||{};c&&c.forEach&&c.forEach(t=>{t.value!=null&&t.value.filter(e=>e!=null&&e.toString().trim()!="").length>0&&(D[t.param]=t.value)}),f&&(D.dvzProxyDatasetId=f);const n=[];return Z(H,w,F),I.jsx("span",{ref:H,children:I.jsx(P.default,{style:{minHeight:`${S}px`},params:D,app:y,group:m,csv:h,editing:l,waitForFilters:M==="true",store:[y,p,...n],source:n.join("/"),children:I.jsx(_.default,{children:I.jsx(O,{locale:R,intl:r,app:y,format:i,measure:o(b)[0]||null,numberFontSize:a,numberColor:V,noDataText:q,textTemplate:C})})})})},O=u=>{var w,F;const{app:l,measure:p,data:r,format:s,numberColor:h,numberFontSize:f,noDataText:z="-",textTemplate:y="",intl:b}=u;let v=p,m=r;l==="csv"&&((w=r==null?void 0:r.meta)!=null&&w.fields)&&((F=r==null?void 0:r.data)!=null&&F.length)&&(v=r.meta.fields[0],m=r.data[0]);const x=(m==null?void 0:m[v])??null,a=x?(s==null?void 0:s.style)==="percent"?x/100:x:null,[V,M]=j.useState(a);j.useEffect(()=>{a!=null&&M(a)},[a]);const q={color:decodeURIComponent(h),fontSize:f+"px",textAlign:"center",whiteSpace:"normal",wordBreak:"break-word"},C=g=>b.formatNumber(g,{...s}),R=g=>{if(!g)return"";let o=String(g);return o=o.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,""),o=o.replace(/\son\w+=(?:"[^"]*"|'[^']*')/gi,""),o},H=()=>{const o={...m&&typeof m=="object"?m:{},measure:v||"",rawValue:x,value:a,formattedValue:a!=null?C(a):z},d=a!==null?C(a):null;let i=decodeURIComponent(y)||"";i=i.replace(/(\%|\#C|\#)\(\s*([^)]*?)\s*\)/g,(c,n,t)=>{const e=t.replace(/\s+/g,"");return`${n}(${e})`});const N=(c,n,t)=>b.formatNumber(c,{maximumFractionDigits:n??2,...t}),T=c=>{const n=o[c];return typeof n=="string"?Number(n):n};i=i.replace(/#C\(\{([a-zA-Z0-9_]+)\}(?:,([0-9]+))?\)/g,(c,n,t)=>{const e=T(n);return e==null||isNaN(e)?"":N(e,t?parseInt(t):2,{notation:"compact"})}),i=i.replace(/#\(\{([a-zA-Z0-9_]+)\}(?:,([0-9]+))?\)/g,(c,n,t)=>{const e=T(n);return e==null||isNaN(e)?"":N(e,t?parseInt(t):2,{style:"decimal"})}),i=i.replace(/%\(\{([a-zA-Z0-9_]+)\}(?:,([0-9]+))?\)/g,(c,n,t)=>{const e=T(n);if(e==null||isNaN(e))return"";const A=e/100;return N(A,t?parseInt(t):2,{style:"percent"})});const S=E.formatContent(i,o,b,!1),D=S&&S.trim().length?S:d??z;return R(D)};return I.jsx("span",{style:q,dangerouslySetInnerHTML:{__html:H()}})},Z=(u,l,p)=>{j.useEffect(()=>{if(!l)return;const r=u.current||document.body,s=()=>{try{const f=(u.current?u.current.scrollHeight:document.body.scrollHeight)||0;window.parent&&f&&window.parent.postMessage({type:"dvz-embed-height",id:p,height:f},"*")}catch{}},h=new MutationObserver(()=>{requestAnimationFrame(s)});return h.observe(r,{childList:!0,subtree:!0,characterData:!0}),setTimeout(s,0),()=>h.disconnect()},[u,l,p])},$=(u,l)=>{const{"data-app":p,"data-group":r}=l,s=u.getIn(["data","measures",p,r]);return s?{injectedMeasures:s}:{}},k={},B=U.connect($,k)(L);exports.default=B;
