"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),O=require("axios"),d=require("../../commons/utils/json2css.js"),B={key:0,class:"weather-temperature__suffix"},E=e.defineComponent({name:"zv-commons-weather"}),D=e.defineComponent({...E,props:{basicOption:{},useEvents:{}},emits:["on-success","on-error"],setup(h,{emit:m}){const n=h,u=m,w=()=>{const a=e.ref(),i=e.ref({city:"",date:"",week:"",dayweather:"",nightweather:"",daytemp:"",nighttemp:"",daywind:"",nightwind:"",daypower:"",nightpower:"",daytemp_float:"",nighttemp_float:""}),s=e.ref(null),c=t=>{O.get(`https://restapi.amap.com/v3/weather/weatherInfo?city=${t.city}&key=${t.key}&extensions=all`).then(r=>{r.status===200&&r.data.status==="1"&&r.data.forecasts.length>0?(u("on-success",r),window.SHJParseEvent(n.useEvents,"on-success",r),i.value=r.data.forecasts[0].casts[0],i.value.city=r.data.forecasts[0].city):(u("on-error",r),window.SHJParseEvent(n.useEvents,"on-error",r))}).catch(()=>{u("on-error",null),window.SHJParseEvent(n.useEvents,"on-error",null)})},S=t=>(t.fontFamily&&d.autoInstallFont(t.fontFamily),{...d.jsonToCssStyle(t),lineHeight:`${t.lineHeight}px`,transform:`translate(${t.transform.x}px, ${t.transform.y}px)`}),k=(t,r)=>{if(r.find(p=>p.name===i.value.dayweather)){const p=r.find(b=>b.name===i.value.dayweather).url||"";return{mask:`url(${p}) 0px 0px / 100% 100%`,width:`${t.size}px`,height:`${t.size}px`,background:`url(${p}) 0px 0px / 100% 100%, ${t.color}`,backgroundBlendMode:"overlay",marginRight:`${t.margin.right}px`}}return{}},y=t=>{s.value&&clearInterval(s.value),t.autoUpdate!==0?s.value=setInterval(()=>c(t),t.autoUpdate*1e3):(clearInterval(s.value),c(t))};return e.onMounted(()=>{c(n.basicOption),y(n.basicOption)}),e.onBeforeUnmount(()=>{s.value&&clearInterval(s.value)}),{initWeatherMessage:c,rendererDomStyle:S,handleAutoUpdate:y,rendererWeatherTypeStyle:k,weatherRef:a,weather:i}},{handleAutoUpdate:f,rendererDomStyle:l,rendererWeatherTypeStyle:g,weatherRef:v,weather:o}=w();return e.watch(()=>n.basicOption,()=>f(n.basicOption),{deep:!0}),(a,i)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"weatherRef",ref:v,class:"zerov-widgets"},[a.basicOption.icon.show?(e.openBlock(),e.createElementBlock("p",{key:0,class:"weather-icon",style:e.normalizeStyle(e.unref(g)(a.basicOption.icon,a.basicOption.icons))},null,4)):e.createCommentVNode("",!0),a.basicOption.weather.city.show?(e.openBlock(),e.createElementBlock("p",{key:1,class:"weather-city",style:e.normalizeStyle(e.unref(l)(a.basicOption.weather.city.textStyle))},e.toDisplayString(e.unref(o).city),5)):e.createCommentVNode("",!0),a.basicOption.weather.type.show?(e.openBlock(),e.createElementBlock("p",{key:2,class:"weather-type",style:e.normalizeStyle(e.unref(l)(a.basicOption.weather.type.textStyle))},e.toDisplayString(e.unref(o).dayweather),5)):e.createCommentVNode("",!0),a.basicOption.weather.wind.show?(e.openBlock(),e.createElementBlock("p",{key:3,class:"weather-wind",style:e.normalizeStyle(e.unref(l)(a.basicOption.weather.wind.textStyle))},e.toDisplayString(e.unref(o).daywind)+"风"+e.toDisplayString(e.unref(o).daypower)+"级 ",5)):e.createCommentVNode("",!0),a.basicOption.weather.temperature.show?(e.openBlock(),e.createElementBlock("p",{key:4,class:"weather-temperature",style:e.normalizeStyle(e.unref(l)(a.basicOption.weather.temperature.textStyle))},[e.createTextVNode(e.toDisplayString(e.unref(o).nighttemp)+" "+e.toDisplayString(a.basicOption.weather.temperature.connectors)+" "+e.toDisplayString(e.unref(o).daytemp)+" ",1),a.basicOption.weather.temperature.suffix.show?(e.openBlock(),e.createElementBlock("span",B,e.toDisplayString(a.basicOption.weather.temperature.suffix.suffix),1)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0)],512))}});exports.default=D;
