"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),g=require("../../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,d=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,s=0;a.value.showMillisecond&&(s=e%1e3,t=t.replace("SSS","0".repeat(3-String(s).length)+s)),e=Math.floor(e/1e3);let r=0;a.value.showYear?(r=Math.floor(e/(60*60*24*30*12)),t=t.includes("YY")?t.replace("YY",i(r)):t.replace("Y",String(r))):r=0;let c=0;a.value.showMonth?(e=e-r*60*60*24*30*12,c=Math.floor(e/(60*60*24*30)),t=t.includes("MM")?t.replace("MM",i(c)):t.replace("M",String(c))):c=0;let u=0;a.value.showDay?(e=e-c*60*60*24*30,u=Math.floor(e/(60*60*24)),t=t.includes("DD")?t.replace("DD",i(u)):t.replace("D",String(u))):u=0;let f=0;a.value.showHour?(e=e-u*60*60*24,f=Math.floor(e/(60*60)),t=t.includes("HH")?t.replace("HH",i(f)):t.replace("H",String(f))):f=0;let p=0;a.value.showMinute?(e=e-f*60*60,p=Math.floor(e/60),t=t.includes("mm")?t.replace("mm",i(p)):t.replace("m",String(p))):p=0;let v=0;return a.value.showSecond&&(v=e-p*60,t=t.includes("ss")?t.replace("ss",i(v)):t.replace("s",String(v))),t}function O(){l.value!==null&&(d.value>Date.now()?(l.value=d.value-Date.now(),S(O)):(l.value=0,m("on-end"),window.SHJParseEvent(o.useEvents,"end-count-down",null)))}const w=()=>{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()&&(d.value=o.basicOption.conf.value):o.basicOption.conf.value>=0&&(d.value=o.basicOption.conf.value+Date.now()),S(O)):l.value=null};n.watchEffect(()=>{o.basicOption.conf.autoStart?w():l.value=null});const h=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 s={};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,...s,...e.textShadow.show?{"--text-shadow":`${e.textShadow.x}px ${e.textShadow.y}px ${e.textShadow.value}px ${e.textShadow.color}`}:{}}};return M({start:()=>w(),startAgain:()=>w()}),(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(h(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(h(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(h(e.basicOption.css)),ztitle:b(l.value)},n.toDisplayString(b(l.value)),13,T)):n.createCommentVNode("",!0)],64))}});exports.default=H;
