import M from"./mCard.1ec5add2.js";import{X as x}from"./index.ad3efb29.js";import{b as C}from"./enum.75055dcb.js";import{d as y,B as V,r as v,k as B,E,w as m,o as f,c as p,F as j,a8 as U,M as w}from"./vue.adf17aba.js";import{_ as D}from"./_plugin-vue_export-helper.c27b6911.js";import"./index.05a2d588.js";import"./elementPlus.4833989a.js";import"./echarts.72dc8373.js";const F={class:"metrics-cards"},O=y({__name:"index",props:{modelValue:{},metricItems:{}},emits:["change","update:modelValue"],setup(_,{emit:h}){const u=V("statDim"),c={},r=_,s=h,o=v(r.modelValue),i=v([]),n=B(()=>{const e={};for(const l of r.metricItems)e[l.value]=l.label;return e}),d=()=>{o.value=[],i.value=[],Object.keys(c).forEach(e=>delete c[e]),u.value==="day"||u.value==="month"?o.value=[{metric:"sales",color:"#0085ff",label:"销售额"},{metric:"sales_last_year",color:"#ff9500",label:"上年销售额"},{metric:"sales_last_month",color:"#3fd4cf",label:"上月销售额"}]:u.value==="week"&&(o.value=C.value);for(const e of o.value)i.value.push({metric:e.metric,color:e.color}),e.color&&(c[e.color]=!0);s("update:modelValue",o.value)};E(d),m(u,d);const b=()=>{for(const[e,l]of Object.entries(c))if(!l)return c[e]=!0,e;return""},k=e=>{x.has(c,e)&&(c[e]=!1)},g=(e,l)=>{for(const a of r.metricItems)a.value===e?a.disabled=!0:a.value===l&&(a.disabled=!1);const t=o.value.findIndex(a=>a.metric===l);t>-1&&(o.value[t].metric=e,o.value[t].label=n.value[e],s("update:modelValue",o.value),s("change",o.value))},I=e=>{const l=o.value.findIndex(t=>t.metric===e);if(l>-1){if(o.value.length<=1)return;const t=o.value[l];o.value.splice(l,1),k(t.color),s("update:modelValue",o.value),s("change",o.value)}else if(o.value.length===3)o.value[2].metric=e,o.value[2].label=n.value[e];else{const t=b();o.value.push({metric:e,color:t,label:n.value[e]})}s("update:modelValue",o.value),s("change",o.value)};return m(o,()=>{const e={};for(const l of o.value)e[l.metric]=l.color;for(const l of i.value){const t=e[l.metric];t?l.color=t:l.color=void 0}},{deep:!0}),m(r.metricItems,()=>{const e={};for(const t of i.value)e[t.metric]=!0;let l=6-i.value.length;if(l>0){for(const t of r.metricItems)if(!e[t.value]&&(i.value.push({metric:t.value}),e[t.value]=!0,l--,l===0))break}for(const t of r.metricItems)e[t.value]?t.disabled=!0:t.disabled=!1}),(e,l)=>(f(),p("div",F,[(f(!0),p(j,null,U(i.value,t=>(f(),w(M,{key:t.metric,modelValue:t.metric,"onUpdate:modelValue":a=>t.metric=a,color:t.color,"metric-items":r.metricItems,onClick:a=>I(t.metric),onChangeMetric:g},null,8,["modelValue","onUpdate:modelValue","color","metric-items","onClick"]))),128))]))}});const G=D(O,[["__scopeId","data-v-21822f78"]]);export{G as default};
