"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),g=require("../../commons/utils/json2css.js"),x=["ztitle"],k=["ztitle"],T=["ztitle"],C=n.defineComponent({name:"zv-text-count-down"}),H=n.defineComponent({...C,props:{basicOption:{},useEvents:{}},emits:["on-end","on-start"],setup(y,{expose:M,emit:D}){const m=D,S=window.requestAnimationFrame,o=y,h=n.ref(0),l=n.ref(0),a=n.computed(()=>({showMillisecond:o.basicOption.conf.format.includes("SSS"),showYear:o.basicOption.conf.format.includes("Y"),showMonth:o.basicOption.conf.format.includes("M"),showDay:o.basicOption.conf.format.includes("D"),showHour:o.basicOption.conf.format.includes("H"),showMinute:o.basicOption.conf.format.includes("m"),showSecond:o.basicOption.conf.format.includes("s")}));function i(e){return e<10?"0"+e:String(e)}function b(e){if(e===null)return"--";let t=o.basicOption.conf.format,r=0;a.value.showMillisecond&&(r=e%1e3,t=t.replace("SSS","0".repeat(3-String(r).length)+r)),e=Math.floor(e/1e3);let c=0;a.value.showYear?(c=Math.floor(e/(60*60*24*30*12)),t=t.includes("YY")?t.replace("YY",i(c)):t.replace("Y",String(c))):c=0;let u=0;a.value.showMonth?(e=e-c*60*60*24*30*12,u=Math.floor(e/(60*60*24*30)),t=t.includes("MM")?t.replace("MM",i(u)):t.replace("M",String(u))):u=0;let f=0;a.value.showDay?(e=e-u*60*60*24*30,f=Math.floor(e/(60*60*24)),t=t.includes("DD")?t.replace("DD",i(f)):t.replace("D",String(f))):f=0;let p=0;a.value.showHour?(e=e-f*60*60*24,p=Math.floor(e/(60*60)),t=t.includes("HH")?t.replace("HH",i(p)):t.replace("H",String(p))):p=0;let d=0;a.value.showMinute?(e=e-p*60*60,d=Math.floor(e/60),t=t.includes("mm")?t.replace("mm",i(d)):t.replace("m",String(d))):d=0;let v=0;return a.value.showSecond&&(v=e-d*60,t=t.includes("ss")?t.replace("ss",i(v)):t.replace("s",String(v))),t}function O(){l.value!==null&&(h.value>Date.now()?(l.value=h.value-Date.now(),S(O)):(l.value=0,m("on-end"),window.SHJParseEvent(o.useEvents,"end-count-down",null)))}const s=()=>{m("on-start"),window.SHJParseEvent(o.useEvents,"on-start",null),l.value=0,Number.isFinite(o.basicOption.conf.value)?(o.basicOption.conf.future?o.basicOption.conf.value>=Date.now()&&(h.value=o.basicOption.conf.value):o.basicOption.conf.value>=0&&(h.value=o.basicOption.conf.value+Date.now()),S(O)):l.value=null};n.watchEffect(()=>{o.basicOption.conf.autoStart?s():l.value=null});const w=e=>{g.autoInstallFont(e.fontFamily);const t={};e.color&&e.color.includes("linear-gradient")&&(t.backgroundImage=e.color,t["-webkit-background-clip"]="text",t.color="transparent");const r={};return e.textAlign==="left"&&(e.justifyContent="flex-start"),e.textAlign==="center"&&(e.justifyContent="center"),e.textAlign==="right"&&(e.justifyContent="flex-end"),{...g.jsonToCssStyle(e),...t,...r,...e.textShadow.show?{"--text-shadow":`${e.textShadow.x}px ${e.textShadow.y}px ${e.textShadow.value}px ${e.textShadow.color}`}:{}}};return M({start:()=>s(),startAgain:()=>s(),refresh:()=>s(),refreshView:()=>s(),refreshData:()=>s()}),(e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,null,[e.basicOption.conf.finishedText&&l.value===0&&l.value!==null?(n.openBlock(),n.createElementBlock("span",{key:0,class:"count-down",style:n.normalizeStyle(w(e.basicOption.css)),ztitle:e.basicOption.conf.finishedText},n.toDisplayString(e.basicOption.conf.finishedText),13,x)):n.createCommentVNode("",!0),e.basicOption.conf.defaultText&&l.value===null?(n.openBlock(),n.createElementBlock("span",{key:1,class:"count-down",style:n.normalizeStyle(w(e.basicOption.css)),ztitle:e.basicOption.conf.defaultText},n.toDisplayString(e.basicOption.conf.defaultText),13,k)):n.createCommentVNode("",!0),Number.isFinite(l.value)&&l.value>0?(n.openBlock(),n.createElementBlock("span",{key:2,class:"count-down",style:n.normalizeStyle(w(e.basicOption.css)),ztitle:b(l.value)},n.toDisplayString(b(l.value)),13,T)):n.createCommentVNode("",!0)],64))}});exports.default=H;
