(function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","vue","dayjs"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d.index={},d.Vue,d.dayjs))})(this,function(d,e,a){"use strict";const y={modelValue:{type:Date,default:new Date},readOnly:{type:Boolean,default:!1}},A="",N="g";function p(n,u,o){let l=n;return u&&(l+=`__${u}`),o&&(l+=`--${o}`),l}function b(n,u=!1){const o=u?`.${N}-${n}`:`${N}-${n}`;return{b:()=>p(o),e:c=>c?p(o,c):"",m:c=>c?p(o,"",c):"",em:(c,Y)=>c&&Y?p(o,c,Y):""}}const g="G",m=e.defineComponent({name:`${g}Calendar`,props:y,emits:["change","update:modelValue"],setup(n,{emit:u,slots:o}){const l=b("calendar"),s=e.ref(n.modelValue?a(n.modelValue).format("YYYY-MM-DD"):a().format("YYYY-MM-DD")),r=e.ref(a().format("YYYY-MM")),D=e.ref([]),c=["周日","周一","周二","周三","周四","周五","周六"],Y=t=>{const f=a(t).startOf("month").day(),h=a(a(t).subtract(7-f,"days")).format("YYYY-MM-DD");D.value=[...Array(42)].map((M,i)=>i).reduce((M,i)=>{const C=a(h).add(i+1,"days").format("YYYY-MM-DD"),x=C.split("-"),T=a(C).day();return M.push({index:i+1,date:C,day:x[x.length-1],week:c[T]}),M},[])};Y(r.value);const V=t=>{s.value=a(t).format("YYYY-MM-DD"),t.indexOf(r.value)===-1&&(r.value=a(t).format("YYYY-MM"),Y(r.value)),u("update:modelValue",new Date(s.value)),u("change",s.value)},v=t=>{let f="";t==="nextMonth"&&(f=a(r.value).add(1,"month").format("YYYY-MM")),t==="lastMonth"&&(f=a(r.value).subtract(1,"month").format("YYYY-MM")),V(f)};e.watch(()=>n.modelValue,()=>{s.value=a(n.modelValue).format("YYYY-MM-DD"),s.value.indexOf(r.value)===-1&&(r.value=a(n.modelValue).format("YYYY-MM"),Y(r.value))});const k=e.computed(()=>D.value.map(t=>{const f=t.date.includes(r.value),h=s.value===t.date,M={"current-month":f,"current-date":h,[l.em("day-box","day")]:!0},i={isSelected:h,date:t.date,day:parseInt(t.day)};return e.createVNode("div",{onClick:()=>{V(i.date)},class:M},[o.dateCell?o.dateCell(i):i.day])})),$=c.map(t=>e.createVNode("div",{class:l.em("week","item")},[t])),O=()=>e.createVNode("div",{class:l.e("header")},[e.createVNode("div",null,[r.value]),e.createVNode("div",null,[e.createVNode(e.resolveComponent("g-button"),{type:"primary",plain:!0,onClick:()=>{v("lastMonth")}},{default:()=>[e.createTextVNode("上个月")]}),e.createVNode(e.resolveComponent("g-button"),{type:"primary",plain:!0,onClick:()=>{V(a().format("YYYY-MM-DD"))}},{default:()=>[e.createTextVNode("今天")]}),e.createVNode(e.resolveComponent("g-button"),{type:"primary",plain:!0,onClick:()=>{v("nextMonth")}},{default:()=>[e.createTextVNode("下个月")]})])]);return()=>e.createVNode("div",{class:l.b()},[o.header?o.header(s.value):O(),e.createVNode("div",{class:l.e("week")},[$]),e.createVNode("div",{class:l.e("day-box")},[k.value])])}});m.install=function(n,u){n.component(u||m.name,m)};const w={title:"Calendar 日历",category:"高级组件",status:"100%",install(n){n.component(m.name,m)}};d.Calendar=m,d.default=w,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
