"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("react/jsx-runtime"),G=require("react"),J=require("semantic-ui-react"),L=require("../data/DataProvider.js"),Q=require("../data/DataConsumer.js");require("@devgateway/wp-react-lib");const W=require("react-redux"),X=require("../utils/common.js"),H=require("string-template"),Z=t=>{const{editing:m=!1,unique:b,intl:h,childContent:v,"data-csv":r="","data-dvz-proxy-dataset-id":c,"data-no-data-message":A="No data matches your selection","data-view-mode":I="info","data-height":y,"data-app":F,"data-measures":q="{}","data-format":U="{}","data-group":g,"data-filters":P="[]","data-text-color":e="#5a5d68","data-number-color":n="#5a5d68","data-percent-color":o="#5a5d68","data-back-ground-color":i="none","data-big-number-font-size":d=20,"data-label-font-size":u=20,"data-percent-font-size":f=20,"data-label":j="","data-dimension1":C,"data-show-percentage-change":w="false","data-wait-for-filters":R="false","data-no-data-text":D="-","data-icon-image":M="","data-icon-up":_="","data-icon-down":k="","data-show-tooltip":N="false","data-tooltip-text":z="","data-tooltip-style":T="light"}=t,l=h.locale,x=G.useRef(null),S=s=>m?s:decodeURIComponent(s),V=s=>{try{return JSON.parse(S(s))}catch{console.error("error parsing value:"+s)}return null},p=V(U),B=p?{style:p.style==="compacted"?"decimal":p.style,notation:p.style==="compacted"?"compact":"standard",currency:p.currency,minimumFractionDigits:parseInt(p.minimumFractionDigits),maximumFractionDigits:parseInt(p.maximumFractionDigits)}:{notation:"standard",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2},[oe,re]=G.useState(I),K=m?y-80:y-40,O={},E=V(P)||{};E&&E.forEach&&E.forEach(s=>{s.value!=null&&s.value.filter($=>$!=null&&$.toString().trim()!="").length>0&&(O[s.param]=s.value)}),c&&(O.dvzProxyDatasetId=c);const Y=[];return C!="none"&&Y.push(C),a.jsx("div",{ref:x,children:a.jsx(J.Container,{className:`chart container big-number-trend-container ${m?"editing":""}`,style:{height:y+"px",backgroundColor:i},fluid:!0,children:a.jsx(L.default,{style:{height:`${K}px`},params:O,app:F,group:g,csv:r,editing:m,waitForFilters:R==="true",store:[F,b,...Y],source:Y.join("/"),children:a.jsx(Q.default,{children:a.jsx(ee,{iconImage:M,iconDown:k,iconUp:_,editing:m,locale:l,intl:h,app:F,format:B,dimension1:C,measure:V(q)[0]||null,label:j,bigNumberFontSize:d,textColor:e,numberColor:n,percentColor:o,backGroundColor:i,labelFontSize:u,percentFontSize:f,showPercentageChange:w=="true"||w==!0,noDataText:D,showTooltip:N=="true"||N===!0,tooltipText:z,tooltipStyle:T})})})})})},ee=t=>{const{editing:m,app:b,measure:h,dimension1:v,data:r,format:c,label:A,textColor:I,bigNumberFontSize:y,percentFontSize:F,labelFontSize:q,showPercentageChange:U,intl:g,noDataText:P}=t;let e=[],n,o;if(b=="csv"){const{data:l,meta:{fields:x}}=r;n=x[0],o=x[1],e=r.data.map(S=>({value:S[n],[o]:S[o],[n]:S[n]}))}else if(e=!r.children||r.children.length==0?[]:r.children,o=h,n=v,n==null||n=="none"){let l={};l[o]=r[o],e=[l]}else e=!r.children||r.children.length==0?[]:r.children,e=e.map(l=>({value:l.value,[o]:l[o],[n]:l.value}));let i=null,d=null,u,f,j;e.length>0&&(e=e.sort((l,x)=>X.alphaSort(!1,g.locale,l.value,x.value)),i=e[e.length-1][o],e.length>1&&(d=e[e.length-2][o]),j=g.formatNumber(c.style==="percent"?i/100:i,{...c}),d&&(u=(i-d)/d,f=g.formatNumber(u,{style:"percent",minimumFractionDigits:2,maximumFractionDigits:2}))),i==null&&(j=P);const C={color:decodeURIComponent(t.numberColor),fontSize:y+"px"},w={color:decodeURIComponent(t.percentColor),fontSize:F+"px"},R={color:decodeURIComponent(I),fontSize:q+"px"},D=e.length>0?e[e.length-1]:{},M=e.length>0?D[n]:null,_=e.length>1?e[e.length-2][n]:null,k=i!=null?g.formatNumber(c.style==="percent"?i/100:i,{...c}):null,N=d!=null?g.formatNumber(c.style==="percent"?d/100:d,{...c}):null,z={...D,current_year:M,previous_year:_,current_value:k,previous_value:N,percent_change:f},T=t.showTooltip&&t.tooltipText?H(t.tooltipText,z):void 0;return a.jsxs("div",{className:"trend",children:[a.jsx("div",{className:"label",style:R,children:H(A,z)}),a.jsxs("div",{className:"number-and-icon",children:[a.jsx("span",{className:"number",style:C,children:j}),u>0&&t.iconUp!=""&&a.jsx("img",{src:t.iconUp}),u<0&&t.iconDown!=""&&a.jsx("img",{src:t.iconDown}),u>0&&t.iconUp==""&&a.jsx("div",{className:"icon trend arrow up"}),u<0&&t.iconDown==""&&a.jsx("div",{className:"icon trend arrow down"})]}),U&&u&&(t.showTooltip&&T?a.jsx(J.Popup,{content:T,position:"top center",inverted:t.tooltipStyle==="dark",size:"small",trigger:a.jsx("div",{className:"percentage",style:w,children:f})}):a.jsx("div",{className:"percentage",style:w,children:f}))]})},te=(t,m)=>{const{"data-app":b,"data-group":h}=m,v=t.getIn(["data","measures",b,h]);return v?{injectedMeasures:v}:{}},ae={},ne=W.connect(te,ae)(Z);exports.default=ne;
