import{noteOnce as e}from"../../vc-util/warning.mjs";import t from"dayjs";import n from"dayjs/plugin/advancedFormat";import r from"dayjs/plugin/customParseFormat";import i from"dayjs/plugin/localeData";import a from"dayjs/plugin/quarterOfYear";import o from"dayjs/plugin/weekOfYear";import s from"dayjs/plugin/weekYear";import c from"dayjs/plugin/weekday";t.extend(r),t.extend(n),t.extend(c),t.extend(i),t.extend(o),t.extend(s),t.extend(a),t.extend((e,t)=>{let n=t.prototype,r=n.format;n.format=function(e){let t=(e||``).replace(`Wo`,`wo`);return r.bind(this)(t)}});var l={bn_BD:`bn-bd`,by_BY:`be`,en_GB:`en-gb`,en_US:`en`,fr_BE:`fr`,fr_CA:`fr-ca`,hy_AM:`hy-am`,kmr_IQ:`ku`,nl_BE:`nl-be`,pt_BR:`pt-br`,zh_CN:`zh-cn`,zh_HK:`zh-hk`,zh_TW:`zh-tw`},u=e=>l[e]||e.split(`_`)[0],d=()=>{e(!1,`Not match any format. Please help to fire a issue about this.`)},f=/\[([^\]]+)\]|Q|wo|ww|w|WW|W|zzz|[zS]|gggg|GGGG|k{1,2}/g;function p(e,t,n){let r=[...new Set(e.split(n))],i=0;for(let e=0;e<r.length;e++){let a=r[e];if(i+=a.length,i>t)return a;i+=n.length}}var m=(e,n)=>{if(!e)return null;if(t.isDayjs(e))return e;let r=n.matchAll(f),i=t(e,n);if(r===null)return i;for(let t of r){let n=t[0],r=t.index;if(n===`Q`){let t=p(e,r,e.slice(r-1,r)).match(/\d+/)[0];i=i.quarter(Number.parseInt(t))}if(n.toLowerCase()===`wo`){let t=p(e,r,e.slice(r-1,r)).match(/\d+/)[0];i=i.week(Number.parseInt(t))}n.toLowerCase()===`ww`&&(i=i.week(Number.parseInt(e.slice(r,r+n.length)))),n.toLowerCase()===`w`&&(i=i.week(Number.parseInt(e.slice(r,r+n.length+1))))}return i},h={getNow:()=>t(),getFixedDate:e=>t(e,[`YYYY-M-DD`,`YYYY-MM-DD`]),getEndDate:e=>e.endOf(`month`),getWeekDay:e=>{let t=e.locale(`en`);return t.weekday()+t.localeData().firstDayOfWeek()},getYear:e=>e.year(),getMonth:e=>e.month(),getDate:e=>e.date(),getHour:e=>e.hour(),getMinute:e=>e.minute(),getSecond:e=>e.second(),addYear:(e,t)=>e.add(t,`year`),addMonth:(e,t)=>e.add(t,`month`),addDate:(e,t)=>e.add(t,`day`),setYear:(e,t)=>e.year(t),setMonth:(e,t)=>e.month(t),setDate:(e,t)=>e.date(t),setHour:(e,t)=>e.hour(t),setMinute:(e,t)=>e.minute(t),setSecond:(e,t)=>e.second(t),isAfter:(e,t)=>e.isAfter(t),isValidate:e=>e.isValid(),locale:{getWeekFirstDay:e=>t().locale(u(e)).localeData().firstDayOfWeek(),getWeekFirstDate:(e,t)=>t.locale(u(e)).weekday(0),getWeek:(e,t)=>t.locale(u(e)).week(),getShortWeekDays:e=>t().locale(u(e)).localeData().weekdaysMin(),getShortMonths:e=>t().locale(u(e)).localeData().monthsShort(),format:(e,t,n)=>t.locale(u(e)).format(n),parse:(e,n,r)=>{let i=u(e);for(let e=0;e<r.length;e+=1){let a=r[e],o=n;if(a.includes(`wo`)||a.includes(`Wo`)){let e=o.split(`-`)[0],n=o.split(`-`)[1],r=t(e,`YYYY`).startOf(`year`).locale(i);for(let e=0;e<=52;e+=1){let t=r.add(e,`week`);if(t.format(`Wo`)===n)return t}return d(),null}let s=t(o,a,!0).locale(i);if(s.isValid())return s}return n||d(),null}},toDate:(e,t)=>Array.isArray(e)?e.map(e=>m(e,t)):m(e,t),toString:(e,n)=>Array.isArray(e)?e.map(e=>t.isDayjs(e)?e.format(n):e):t.isDayjs(e)?e.format(n):e};export{h as default};