import{r as B,P as v,ac as $,J as H,L as I,j as w,g as s,D as b,p as m,Y as p,c as O,ad as j,F as A,Q as J,a1 as y,ae as E,a9 as L,i as Q,e as R,M as C}from"./vendor-vue-gvI8EVHg.js";import{b as S,a as q}from"./index-DCLQfd0E.js";import{u as G}from"./vendor-i18n-DnQQ95F5.js";const W={class:"date-picker-icon"},X={class:"date-picker-value"},Z={class:"date-picker-chevron"},ee={key:0,class:"date-picker-dropdown"},te={class:"date-picker-presets"},ae=["onClick"],se={class:"date-picker-custom"},ne={class:"date-picker-field"},oe={class:"date-picker-label"},le=["max"],re={class:"date-picker-separator"},ce={class:"date-picker-field"},de={class:"date-picker-label"},ue=["min","max"],ie={class:"date-picker-actions"},ve=B({__name:"DateRangePicker",props:{startDate:{},endDate:{}},emits:["update:startDate","update:endDate","change"],setup(F,{emit:z}){const g=F,h=z,{t:d,locale:P}=G(),r=v(!1),k=v(null),n=v(g.startDate),o=v(g.endDate),c=v("last24Hours"),u=R(()=>{const e=new Date,t=e.getFullYear(),a=String(e.getMonth()+1).padStart(2,"0"),D=String(e.getDate()).padStart(2,"0");return`${t}-${a}-${D}`}),M=R(()=>{const e=new Date;return e.setDate(e.getDate()+1),l(e)}),l=e=>{const t=e.getFullYear(),a=String(e.getMonth()+1).padStart(2,"0"),D=String(e.getDate()).padStart(2,"0");return`${t}-${a}-${D}`},_=[{labelKey:"dates.today",value:"today",getRange:()=>{const e=u.value;return{start:e,end:e}}},{labelKey:"dates.yesterday",value:"yesterday",getRange:()=>{const e=new Date;e.setDate(e.getDate()-1);const t=l(e);return{start:t,end:t}}},{labelKey:"dates.last24Hours",value:"last24Hours",getRange:()=>{const e=new Date,t=new Date(e.getTime()-24*60*60*1e3);return{start:l(t),end:l(e)}}},{labelKey:"dates.last7Days",value:"7days",getRange:()=>{const e=u.value,t=new Date;return t.setDate(t.getDate()-6),{start:l(t),end:e}}},{labelKey:"dates.last14Days",value:"14days",getRange:()=>{const e=u.value,t=new Date;return t.setDate(t.getDate()-13),{start:l(t),end:e}}},{labelKey:"dates.last30Days",value:"30days",getRange:()=>{const e=u.value,t=new Date;return t.setDate(t.getDate()-29),{start:l(t),end:e}}},{labelKey:"dates.thisMonth",value:"thisMonth",getRange:()=>{const e=new Date;return{start:l(new Date(e.getFullYear(),e.getMonth(),1)),end:u.value}}},{labelKey:"dates.lastMonth",value:"lastMonth",getRange:()=>{const e=new Date,t=l(new Date(e.getFullYear(),e.getMonth()-1,1)),a=l(new Date(e.getFullYear(),e.getMonth(),0));return{start:t,end:a}}}],V=R(()=>{if(c.value){const e=_.find(t=>t.value===c.value);if(e)return d(e.labelKey)}return n.value&&o.value?n.value===o.value?f(n.value):`${f(n.value)} - ${f(o.value)}`:d("dates.selectDateRange")}),f=e=>{const t=new Date(e+"T00:00:00"),a=P.value==="zh"?"zh-CN":"en-US";return t.toLocaleDateString(a,{month:"short",day:"numeric"})},Y=e=>c.value===e.value,T=e=>{const t=e.getRange();n.value=t.start,o.value=t.end,c.value=e.value},i=()=>{c.value=null;for(const e of _){const t=e.getRange();if(t.start===n.value&&t.end===o.value){c.value=e.value;break}}},N=()=>{r.value=!r.value},U=()=>{h("update:startDate",n.value),h("update:endDate",o.value),h("change",{startDate:n.value,endDate:o.value,preset:c.value}),r.value=!1},x=e=>{k.value&&!k.value.contains(e.target)&&(r.value=!1)},K=e=>{e.key==="Escape"&&r.value&&(r.value=!1)};return $(()=>g.startDate,e=>{n.value=e,i()}),$(()=>g.endDate,e=>{o.value=e,i()}),H(()=>{document.addEventListener("click",x),document.addEventListener("keydown",K),i()}),I(()=>{document.removeEventListener("click",x),document.removeEventListener("keydown",K)}),(e,t)=>(C(),w("div",{class:"relative",ref_key:"containerRef",ref:k},[s("button",{type:"button",onClick:N,class:b(["date-picker-trigger",r.value&&"date-picker-trigger-open"])},[s("span",W,[m(S,{name:"calendar",size:"sm"})]),s("span",X,p(V.value),1),s("span",Z,[m(S,{name:"chevronDown",size:"sm",class:b(["transition-transform duration-200",r.value&&"rotate-180"])},null,8,["class"])])],2),m(O,{name:"date-picker-dropdown"},{default:j(()=>[r.value?(C(),w("div",ee,[s("div",te,[(C(),w(A,null,J(_,a=>s("button",{key:a.value,onClick:D=>T(a),class:b(["date-picker-preset",Y(a)&&"date-picker-preset-active"])},p(y(d)(a.labelKey)),11,ae)),64))]),t[2]||(t[2]=s("div",{class:"date-picker-divider"},null,-1)),s("div",se,[s("div",ne,[s("label",oe,p(y(d)("dates.startDate")),1),E(s("input",{type:"date","onUpdate:modelValue":t[0]||(t[0]=a=>n.value=a),max:o.value||M.value,class:"date-picker-input",onChange:i},null,40,le),[[L,n.value]])]),s("div",re,[m(S,{name:"arrowRight",size:"sm",class:"text-gray-400"})]),s("div",ce,[s("label",de,p(y(d)("dates.endDate")),1),E(s("input",{type:"date","onUpdate:modelValue":t[1]||(t[1]=a=>o.value=a),min:n.value,max:M.value,class:"date-picker-input",onChange:i},null,40,ue),[[L,o.value]])])]),s("div",ie,[s("button",{onClick:U,class:"date-picker-apply"},p(y(d)("dates.apply")),1)])])):Q("",!0)]),_:1})],512))}}),me=q(ve,[["__scopeId","data-v-4b701320"]]);export{me as D};
