@forcecalendar/interface 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@
12
12
  ${this.getBaseStyles()}
13
13
  ${this.getStyles()}
14
14
  </style>
15
- `,t=this.template();this.shadowRoot.innerHTML=e+t,this.afterRender()}template(){return""}afterRender(){}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}static get observedAttributes(){return[]}attributeChangedCallback(e,t,s){this.setProp(e,s),this._initialized&&this.render()}}class C{constructor(){this.timezones={UTC:{offset:0,dst:null},GMT:{offset:0,dst:null},"Africa/Abidjan":{offset:0,dst:null},"Africa/Accra":{offset:0,dst:null},"Africa/Addis_Ababa":{offset:180,dst:null},"Africa/Algiers":{offset:60,dst:null},"Africa/Cairo":{offset:120,dst:null},"Africa/Casablanca":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Africa/Johannesburg":{offset:120,dst:null},"Africa/Lagos":{offset:60,dst:null},"Africa/Nairobi":{offset:180,dst:null},"America/Anchorage":{offset:-540,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Argentina/Buenos_Aires":{offset:-180,dst:null},"America/Bogota":{offset:-300,dst:null},"America/Caracas":{offset:-240,dst:null},"America/Chicago":{offset:-360,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Denver":{offset:-420,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Detroit":{offset:-300,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Halifax":{offset:-240,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Los_Angeles":{offset:-480,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Mexico_City":{offset:-360,dst:{start:{month:4,week:1,day:0},end:{month:10,week:-1,day:0},offset:60}},"America/New_York":{offset:-300,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Phoenix":{offset:-420,dst:null},"America/Regina":{offset:-360,dst:null},"America/Santiago":{offset:-180,dst:{start:{month:9,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"America/Sao_Paulo":{offset:-180,dst:{start:{month:10,week:3,day:0},end:{month:2,week:3,day:0},offset:60}},"America/St_Johns":{offset:-210,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Toronto":{offset:-300,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Vancouver":{offset:-480,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"Asia/Baghdad":{offset:180,dst:null},"Asia/Bangkok":{offset:420,dst:null},"Asia/Dubai":{offset:240,dst:null},"Asia/Hong_Kong":{offset:480,dst:null},"Asia/Jakarta":{offset:420,dst:null},"Asia/Jerusalem":{offset:120,dst:{start:{month:3,week:-1,day:5},end:{month:10,week:-1,day:0},offset:60}},"Asia/Karachi":{offset:300,dst:null},"Asia/Kolkata":{offset:330,dst:null},"Asia/Kuala_Lumpur":{offset:480,dst:null},"Asia/Manila":{offset:480,dst:null},"Asia/Seoul":{offset:540,dst:null},"Asia/Shanghai":{offset:480,dst:null},"Asia/Singapore":{offset:480,dst:null},"Asia/Taipei":{offset:480,dst:null},"Asia/Tehran":{offset:210,dst:{start:{month:3,week:4,day:0},end:{month:9,week:4,day:0},offset:60}},"Asia/Tokyo":{offset:540,dst:null},"Atlantic/Azores":{offset:-60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Atlantic/Bermuda":{offset:-240,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"Atlantic/Reykjavik":{offset:0,dst:null},"Australia/Adelaide":{offset:570,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Australia/Brisbane":{offset:600,dst:null},"Australia/Darwin":{offset:570,dst:null},"Australia/Hobart":{offset:600,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Australia/Melbourne":{offset:600,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Australia/Perth":{offset:480,dst:null},"Australia/Sydney":{offset:600,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Europe/Amsterdam":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Athens":{offset:120,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Berlin":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Brussels":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Budapest":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Copenhagen":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Dublin":{offset:0,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Helsinki":{offset:120,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Istanbul":{offset:180,dst:null},"Europe/Kiev":{offset:120,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Lisbon":{offset:0,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/London":{offset:0,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Madrid":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Moscow":{offset:180,dst:null},"Europe/Oslo":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Paris":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Prague":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Rome":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Stockholm":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Vienna":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Warsaw":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Zurich":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Indian/Maldives":{offset:300,dst:null},"Indian/Mauritius":{offset:240,dst:null},"Pacific/Auckland":{offset:720,dst:{start:{month:9,week:-1,day:0},end:{month:4,week:1,day:0},offset:60}},"Pacific/Fiji":{offset:720,dst:{start:{month:11,week:1,day:0},end:{month:1,week:3,day:0},offset:60}},"Pacific/Guam":{offset:600,dst:null},"Pacific/Honolulu":{offset:-600,dst:null},"Pacific/Midway":{offset:-660,dst:null},"Pacific/Noumea":{offset:660,dst:null},"Pacific/Pago_Pago":{offset:-660,dst:null},"Pacific/Port_Moresby":{offset:600,dst:null},"Pacific/Tahiti":{offset:-600,dst:null}},this.aliases={EST:"America/New_York",EDT:"America/New_York",CST:"America/Chicago",CDT:"America/Chicago",MST:"America/Denver",MDT:"America/Denver",PST:"America/Los_Angeles",PDT:"America/Los_Angeles",AKST:"America/Anchorage",AKDT:"America/Anchorage",HST:"Pacific/Honolulu",AST:"America/Halifax",ADT:"America/Halifax",NST:"America/St_Johns",NDT:"America/St_Johns",BST:"Europe/London",IST:"Asia/Kolkata",WET:"Europe/Lisbon",WEST:"Europe/Lisbon",CET:"Europe/Paris",CEST:"Europe/Paris",EET:"Europe/Athens",EEST:"Europe/Athens",MSK:"Europe/Moscow",JST:"Asia/Tokyo",KST:"Asia/Seoul",CST_CN:"Asia/Shanghai",HKT:"Asia/Hong_Kong",SGT:"Asia/Singapore",AEST:"Australia/Sydney",AEDT:"Australia/Sydney",ACST:"Australia/Adelaide",ACDT:"Australia/Adelaide",AWST:"Australia/Perth",NZST:"Pacific/Auckland",NZDT:"Pacific/Auckland","US/Eastern":"America/New_York","US/Central":"America/Chicago","US/Mountain":"America/Denver","US/Pacific":"America/Los_Angeles","US/Alaska":"America/Anchorage","US/Hawaii":"Pacific/Honolulu","Canada/Eastern":"America/Toronto","Canada/Central":"America/Regina","Canada/Mountain":"America/Denver","Canada/Pacific":"America/Vancouver","Canada/Atlantic":"America/Halifax","Canada/Newfoundland":"America/St_Johns","Mexico/General":"America/Mexico_City","Brazil/East":"America/Sao_Paulo","Chile/Continental":"America/Santiago",GB:"Europe/London","GB-Eire":"Europe/London",Eire:"Europe/Dublin",Israel:"Asia/Jerusalem",Japan:"Asia/Tokyo",Singapore:"Asia/Singapore",Hongkong:"Asia/Hong_Kong",ROK:"Asia/Seoul",PRC:"Asia/Shanghai","Australia/NSW":"Australia/Sydney","Australia/Victoria":"Australia/Melbourne","Australia/Queensland":"Australia/Brisbane","Australia/South":"Australia/Adelaide","Australia/Tasmania":"Australia/Hobart","Australia/West":"Australia/Perth","Australia/North":"Australia/Darwin",NZ:"Pacific/Auckland"}}getTimezone(e){return this.aliases[e]&&(e=this.aliases[e]),this.timezones[e]||null}getAllTimezones(){return Object.keys(this.timezones)}isValidTimezone(e){return this.aliases[e]!==void 0||this.timezones[e]!==void 0}resolveAlias(e){return this.aliases[e]||e}getTimezonesByOffset(e){return Object.entries(this.timezones).filter(([t,s])=>s.offset===e).map(([t,s])=>t)}getCommonTimezones(){return{Americas:["America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Mexico_City","America/Sao_Paulo"],Europe:["Europe/London","Europe/Paris","Europe/Berlin","Europe/Moscow","Europe/Rome","Europe/Madrid","Europe/Amsterdam"],Asia:["Asia/Tokyo","Asia/Shanghai","Asia/Hong_Kong","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Asia/Seoul"],"Australia/Pacific":["Australia/Sydney","Australia/Melbourne","Australia/Brisbane","Australia/Perth","Pacific/Auckland","Pacific/Honolulu"],Africa:["Africa/Cairo","Africa/Lagos","Africa/Johannesburg","Africa/Nairobi"]}}}class A{constructor(){this.database=new C,this.offsetCache=new Map,this.dstCache=new Map,this.maxCacheSize=1e3,this.cacheHits=0,this.cacheMisses=0}convertTimezone(e,t,s){if(!e)return null;if(t===s)return new Date(e);const i=this.getTimezoneOffset(e,t),n=(this.getTimezoneOffset(e,s)-i)*60*1e3;return new Date(e.getTime()+n)}toUTC(e,t){if(!e)return null;if(t==="UTC")return new Date(e);const s=this.getTimezoneOffset(e,t);return new Date(e.getTime()+s*60*1e3)}fromUTC(e,t){if(!e)return null;if(t==="UTC")return new Date(e);const s=this.getTimezoneOffset(e,t);return new Date(e.getTime()-s*60*1e3)}getTimezoneOffset(e,t){t=this.database.resolveAlias(t);const s=`${t}_${e.getFullYear()}_${e.getMonth()}_${e.getDate()}`;if(this.offsetCache.has(s))return this.cacheHits++,this._manageCacheSize(),this.offsetCache.get(s);if(this.cacheMisses++,typeof Intl<"u"&&Intl.DateTimeFormat)try{const r=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(e),c=(new Date(r.find(l=>l.type==="year").value,r.find(l=>l.type==="month").value-1,r.find(l=>l.type==="day").value,r.find(l=>l.type==="hour").value,r.find(l=>l.type==="minute").value,r.find(l=>l.type==="second").value).getTime()-e.getTime())/(1e3*60);return this.offsetCache.set(s,-c),this._manageCacheSize(),-c}catch{}const i=this.database.getTimezone(t);if(!i)throw new Error(`Unknown timezone: ${t}`);let a=i.offset;return i.dst&&this.isDST(e,t,i.dst)&&(a+=i.dst.offset),this.offsetCache.set(s,a),this._manageCacheSize(),a}isDST(e,t,s=null){if(!s){const r=this.database.getTimezone(t);if(!r||!r.dst)return!1;s=r.dst}const i=e.getFullYear(),a=this.getNthWeekdayOfMonth(i,s.start.month,s.start.week,s.start.day),n=this.getNthWeekdayOfMonth(i,s.end.month,s.end.week,s.end.day);return a>n?e>=a||e<n:e>=a&&e<n}getNthWeekdayOfMonth(e,t,s,i){const a=new Date(e,t,1),n=a.getDay();let r=i-n;if(r<0&&(r+=7),s>0)a.setDate(1+r+(s-1)*7);else{const o=new Date(e,t+1,0).getDate();a.setDate(o);let l=a.getDay()-i;l<0&&(l+=7),a.setDate(o-l+(s+1)*7)}return a}getCommonTimezones(){const e=new Date;return[{value:"America/New_York",label:"Eastern Time (New York)",region:"Americas"},{value:"America/Chicago",label:"Central Time (Chicago)",region:"Americas"},{value:"America/Denver",label:"Mountain Time (Denver)",region:"Americas"},{value:"America/Phoenix",label:"Mountain Time - Arizona (Phoenix)",region:"Americas"},{value:"America/Los_Angeles",label:"Pacific Time (Los Angeles)",region:"Americas"},{value:"America/Anchorage",label:"Alaska Time (Anchorage)",region:"Americas"},{value:"Pacific/Honolulu",label:"Hawaii Time (Honolulu)",region:"Pacific"},{value:"America/Toronto",label:"Eastern Time (Toronto)",region:"Americas"},{value:"America/Vancouver",label:"Pacific Time (Vancouver)",region:"Americas"},{value:"America/Mexico_City",label:"Central Time (Mexico City)",region:"Americas"},{value:"America/Sao_Paulo",label:"Brasilia Time (São Paulo)",region:"Americas"},{value:"Europe/London",label:"GMT/BST (London)",region:"Europe"},{value:"Europe/Paris",label:"Central European Time (Paris)",region:"Europe"},{value:"Europe/Berlin",label:"Central European Time (Berlin)",region:"Europe"},{value:"Europe/Moscow",label:"Moscow Time",region:"Europe"},{value:"Asia/Dubai",label:"Gulf Time (Dubai)",region:"Asia"},{value:"Asia/Kolkata",label:"India Time (Mumbai)",region:"Asia"},{value:"Asia/Shanghai",label:"China Time (Shanghai)",region:"Asia"},{value:"Asia/Tokyo",label:"Japan Time (Tokyo)",region:"Asia"},{value:"Asia/Seoul",label:"Korea Time (Seoul)",region:"Asia"},{value:"Asia/Singapore",label:"Singapore Time",region:"Asia"},{value:"Australia/Sydney",label:"Australian Eastern Time (Sydney)",region:"Oceania"},{value:"Australia/Melbourne",label:"Australian Eastern Time (Melbourne)",region:"Oceania"},{value:"Pacific/Auckland",label:"New Zealand Time (Auckland)",region:"Oceania"},{value:"UTC",label:"UTC",region:"UTC"}].map(s=>{const i=this.getTimezoneOffset(e,s.value),a=-i/60,n=Math.floor(Math.abs(a)),r=Math.round(Math.abs(a%1)*60),c=`UTC${a>=0?"+":"-"}${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`;return{...s,offset:c,offsetMinutes:-i}}).sort((s,i)=>s.offsetMinutes-i.offsetMinutes)}formatInTimezone(e,t,s={}){if(!e)return"";const a={...{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:t},...s};try{return new Intl.DateTimeFormat("en-US",a).format(e)}catch{return this.fromUTC(this.toUTC(e,"UTC"),t).toLocaleString("en-US",s)}}getSystemTimezone(){if(typeof Intl<"u"&&Intl.DateTimeFormat)try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}const t=-new Date().getTimezoneOffset()/60;for(const[s,i]of Object.entries(this.database.timezones))if(i.offset/60===t)return s;return"UTC"}parseTimezone(e){if(!e)return"UTC";if(this.database.timezones.hasOwnProperty(e))return e;const t=e.toUpperCase();if(this.database.abbreviations&&this.database.abbreviations.hasOwnProperty(t))return this.database.abbreviations[t];const s=e.match(/^([+-])(\d{2}):?(\d{2})$/);if(s){const i=s[1]==="+"?1:-1,a=parseInt(s[2],10),n=parseInt(s[3],10),r=i*(a+n/60);for(const[o,c]of Object.entries(this.database.timezones))if(c.offset/60===r)return o}return"UTC"}getTimezoneDifference(e,t,s=new Date){const i=this.getTimezoneOffset(s,e);return(this.getTimezoneOffset(s,t)-i)/60}clearCache(){this.offsetCache.clear(),this.dstCache.clear(),this.cacheHits=0,this.cacheMisses=0}isValidTimezone(e){return this.database.isValidTimezone(e)}getCacheStats(){const e=this.cacheHits+this.cacheMisses>0?(this.cacheHits/(this.cacheHits+this.cacheMisses)*100).toFixed(2):0;return{offsetCacheSize:this.offsetCache.size,dstCacheSize:this.dstCache.size,maxCacheSize:this.maxCacheSize,cacheHits:this.cacheHits,cacheMisses:this.cacheMisses,hitRate:`${e}%`}}_manageCacheSize(){if(this.offsetCache.size>this.maxCacheSize){const e=Math.floor(this.offsetCache.size/2),t=Array.from(this.offsetCache.keys());for(let s=0;s<e;s++)this.offsetCache.delete(t[s])}if(this.dstCache.size>this.maxCacheSize/2){const e=Math.floor(this.dstCache.size/2),t=Array.from(this.dstCache.keys());for(let s=0;s<e;s++)this.dstCache.delete(t[s])}}}class E{static normalize(e){const t={...e};return t.start&&!(t.start instanceof Date)&&(t.start=new Date(t.start)),t.end&&!(t.end instanceof Date)&&(t.end=new Date(t.end)),t.end||(t.end=t.start?new Date(t.start):null),t.allDay&&t.start&&(t.start.setHours(0,0,0,0),t.end&&t.end.setHours(23,59,59,999)),t.id=String(t.id||"").trim(),t.title=String(t.title||"").trim(),t.description=String(t.description||"").trim(),t.location=String(t.location||"").trim(),t.attendees=Array.isArray(t.attendees)?t.attendees:[],t.reminders=Array.isArray(t.reminders)?t.reminders:[],e.category&&!e.categories?t.categories=[e.category]:t.categories?t.categories=Array.isArray(t.categories)?t.categories:[]:t.categories=[],t.attachments=Array.isArray(t.attachments)?t.attachments:[],["confirmed","tentative","cancelled"].includes(t.status)||(t.status="confirmed"),["public","private","confidential"].includes(t.visibility)||(t.visibility="public"),t.color&&!t.backgroundColor&&(t.backgroundColor=t.color),t.color&&!t.borderColor&&(t.borderColor=t.color),t}static validate(e){if(!e.id)throw new Error("Event must have an id");if(!e.title)throw new Error("Event must have a title");if(!e.start)throw new Error("Event must have a start date");if(!(e.start instanceof Date)||isNaN(e.start.getTime()))throw new Error("Invalid start date");if(e.end&&(!(e.end instanceof Date)||isNaN(e.end.getTime())))throw new Error("Invalid end date");if(e.end&&e.start&&e.end<e.start)throw new Error("Event end time cannot be before start time");if(e.recurring&&!e.recurrenceRule)throw new Error("Recurring events must have a recurrence rule");if(e.attendees&&e.attendees.length>0&&e.attendees.forEach((t,s)=>{if(!t.email||!t.name)throw new Error(`Attendee at index ${s} must have email and name`);if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.email))throw new Error(`Invalid email for attendee: ${t.email}`)}),e.reminders&&e.reminders.length>0&&e.reminders.forEach((t,s)=>{if(!t.method||t.minutesBefore==null)throw new Error(`Reminder at index ${s} must have method and minutesBefore`);if(t.minutesBefore<0)throw new Error("Reminder minutesBefore must be non-negative")}),e.timeZone)try{new Intl.DateTimeFormat("en-US",{timeZone:e.timeZone})}catch{throw new Error(`Invalid timezone: ${e.timeZone}`)}}constructor({id:e,title:t,start:s,end:i,allDay:a=!1,description:n="",location:r="",color:o=null,backgroundColor:c=null,borderColor:l=null,textColor:d=null,recurring:h=!1,recurrenceRule:b=null,timeZone:D=null,endTimeZone:k=null,status:S="confirmed",visibility:M="public",organizer:I=null,attendees:q=[],reminders:K=[],category:G,categories:Q,attachments:J=[],conferenceData:X=null,metadata:ee={},...te}){const u=E.normalize({id:e,title:t,start:s,end:i,allDay:a,description:n,location:r,color:o,backgroundColor:c,borderColor:l,textColor:d,recurring:h,recurrenceRule:b,timeZone:D,endTimeZone:k,status:S,visibility:M,organizer:I,attendees:q,reminders:K,category:G,categories:Q,attachments:J,conferenceData:X,metadata:ee,...te});E.validate(u),this.id=u.id,this.title=u.title,this._timezoneManager=new A,this.timeZone=u.timeZone||this._timezoneManager.getSystemTimezone(),this.endTimeZone=u.endTimeZone||this.timeZone,this.start=u.start,this.end=u.end,this.startUTC=this._timezoneManager.toUTC(this.start,this.timeZone),this.endUTC=this._timezoneManager.toUTC(this.end,this.endTimeZone),this.allDay=u.allDay,this.description=u.description,this.location=u.location,this.color=u.color,this.backgroundColor=u.backgroundColor,this.borderColor=u.borderColor,this.textColor=u.textColor,this.recurring=u.recurring,this.recurrenceRule=u.recurrenceRule,this._originalTimeZone=u.timeZone||null,this.status=u.status,this.visibility=u.visibility,this.organizer=u.organizer,this.attendees=[...u.attendees],this.reminders=[...u.reminders],this.categories=u.categories?[...u.categories]:[],this.attachments=[...u.attachments],this.conferenceData=u.conferenceData,this.metadata={...u.metadata},this._cache={},this._validateAttendees(),this._validateReminders()}get duration(){return this._cache.duration||(this._cache.duration=this.endUTC.getTime()-this.startUTC.getTime()),this._cache.duration}getStartInTimezone(e){return e===this.timeZone?new Date(this.start):this._timezoneManager.fromUTC(this.startUTC,e)}getEndInTimezone(e){return e===this.endTimeZone?new Date(this.end):this._timezoneManager.fromUTC(this.endUTC,e)}updateTimes(e,t,s){if(s||this.timeZone,this.start=e instanceof Date?e:new Date(e),this.end=t instanceof Date?t:new Date(t),s&&(this.timeZone=s,this.endTimeZone=s),this.startUTC=this._timezoneManager.toUTC(this.start,this.timeZone),this.endUTC=this._timezoneManager.toUTC(this.end,this.endTimeZone),this._cache={},this.endUTC<this.startUTC)throw new Error("Event end time cannot be before start time")}get durationMinutes(){return Math.floor(this.duration/(1e3*60))}get durationHours(){return this.duration/(1e3*60*60)}get isMultiDay(){if(!this._cache.hasOwnProperty("isMultiDay")){const e=this.start.toDateString(),t=this.end.toDateString();this._cache.isMultiDay=e!==t}return this._cache.isMultiDay}isRecurring(){return this.recurring&&this.recurrenceRule!==null}occursOn(e){e instanceof Date||(e=new Date(e));const t=e.toDateString(),s=this.start.toDateString(),i=this.end.toDateString();if(this.allDay)return e>=new Date(s)&&e<=new Date(i);if(this.isMultiDay){const a=new Date(t),n=new Date(t);return n.setHours(23,59,59,999),this.start<=n&&this.end>=a}else return s===t}overlaps(e){if(e instanceof E)return!(this.end<=e.start||this.start>=e.end);if(e&&e.start&&e.end)return!(this.end<=e.start||this.start>=e.end);throw new Error("Parameter must be an Event instance or have start/end properties")}contains(e){return e instanceof Date||(e=new Date(e)),e>=this.start&&e<=this.end}clone(e={}){return new E({id:this.id,title:this.title,start:new Date(this.start),end:new Date(this.end),allDay:this.allDay,description:this.description,location:this.location,color:this.color,backgroundColor:this.backgroundColor,borderColor:this.borderColor,textColor:this.textColor,recurring:this.recurring,recurrenceRule:this.recurrenceRule,timeZone:this.timeZone,status:this.status,visibility:this.visibility,organizer:this.organizer?{...this.organizer}:null,attendees:this.attendees.map(t=>({...t})),reminders:this.reminders.map(t=>({...t})),categories:[...this.categories],attachments:this.attachments.map(t=>({...t})),conferenceData:this.conferenceData?{...this.conferenceData}:null,metadata:{...this.metadata},...e})}toObject(){return{id:this.id,title:this.title,start:this.start.toISOString(),end:this.end.toISOString(),allDay:this.allDay,description:this.description,location:this.location,color:this.color,backgroundColor:this.backgroundColor,borderColor:this.borderColor,textColor:this.textColor,recurring:this.recurring,recurrenceRule:this.recurrenceRule,timeZone:this.timeZone,status:this.status,visibility:this.visibility,organizer:this.organizer,attendees:this.attendees,reminders:this.reminders,categories:this.categories,attachments:this.attachments,conferenceData:this.conferenceData,metadata:{...this.metadata}}}static fromObject(e){return new E(e)}equals(e){return e instanceof E?this.id===e.id&&this.title===e.title&&this.start.getTime()===e.start.getTime()&&this.end.getTime()===e.end.getTime()&&this.allDay===e.allDay&&this.description===e.description&&this.location===e.location&&this.recurring===e.recurring&&this.recurrenceRule===e.recurrenceRule&&this.status===e.status:!1}addAttendee(e){if(!e||!e.email)throw new Error("Attendee must have an email");return this.hasAttendee(e.email)?!1:(e.id||(e.id=`attendee_${Date.now()}_${Math.random().toString(36).substr(2,9)}`),e.responseStatus=e.responseStatus||"needs-action",e.role=e.role||"required",this.attendees.push(e),!0)}removeAttendee(e){const t=this.attendees.findIndex(s=>s.email===e||s.id===e);return t!==-1?(this.attendees.splice(t,1),!0):!1}updateAttendeeResponse(e,t){const s=this.getAttendee(e);return s?(s.responseStatus=t,s.responseTime=new Date,!0):!1}getAttendee(e){return this.attendees.find(t=>t.email===e)||null}hasAttendee(e){return this.attendees.some(t=>t.email===e)}getAttendeesByStatus(e){return this.attendees.filter(t=>t.responseStatus===e)}getAttendeeCounts(){return this.attendees.reduce((e,t)=>{const s=t.responseStatus||"needs-action";return e[s]=(e[s]||0)+1,e},{})}addReminder(e){if(!e||typeof e.minutesBefore!="number")throw new Error("Reminder must have minutesBefore property");return e.id||(e.id=`reminder_${Date.now()}_${Math.random().toString(36).substr(2,9)}`),e.method=e.method||"popup",e.enabled=e.enabled!==!1,this.reminders.some(s=>s.method===e.method&&s.minutesBefore===e.minutesBefore)?!1:(this.reminders.push(e),!0)}removeReminder(e){const t=this.reminders.findIndex(s=>s.id===e);return t!==-1?(this.reminders.splice(t,1),!0):!1}getActiveReminders(){return this.reminders.filter(e=>e.enabled!==!1)}getReminderTriggerTimes(){return this.getActiveReminders().map(e=>{const t=new Date(this.start);return t.setMinutes(t.getMinutes()-e.minutesBefore),t})}addCategory(e){if(!e||typeof e!="string")throw new Error("Category must be a non-empty string");const t=e.trim().toLowerCase();return this.hasCategory(t)?!1:(this.categories.push(t),!0)}removeCategory(e){const t=e.trim().toLowerCase(),s=this.categories.findIndex(i=>i.toLowerCase()===t);return s!==-1?(this.categories.splice(s,1),!0):!1}get category(){return this.categories&&this.categories.length>0?this.categories[0]:null}hasCategory(e){const t=e.trim().toLowerCase();return this.categories.some(s=>s.toLowerCase()===t)}hasAnyCategory(e){return e.some(t=>this.hasCategory(t))}hasAllCategories(e){return e.every(t=>this.hasCategory(t))}_validateAttendees(){for(const e of this.attendees){if(!e.email)throw new Error("All attendees must have an email address");if(e.name||(e.name=e.email),!this._isValidEmail(e.email))throw new Error(`Invalid attendee email: ${e.email}`)}}_validateReminders(){for(const e of this.reminders){if(typeof e.minutesBefore!="number"||e.minutesBefore<0)throw new Error("Reminder minutesBefore must be a positive number");if(!["email","popup","sms"].includes(e.method))throw new Error(`Invalid reminder method: ${e.method}`)}}_isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}get isCancelled(){return this.status==="cancelled"}get isTentative(){return this.status==="tentative"}get isConfirmed(){return this.status==="confirmed"}get isPrivate(){return this.visibility==="private"}get isPublic(){return this.visibility==="public"}get hasAttendees(){return this.attendees.length>0}get hasReminders(){return this.reminders.length>0}get isMeeting(){return this.hasAttendees||this.conferenceData!==null}get isVirtual(){return this.conferenceData!==null}}let f=class x{static startOfDay(e){const t=new Date(e);return t.setHours(0,0,0,0),t}static endOfDay(e){const t=new Date(e);return t.setHours(23,59,59,999),t}static startOfWeek(e,t=0){const s=new Date(e),i=s.getDay(),a=(i<t?7:0)+i-t;return s.setTime(s.getTime()-a*24*60*60*1e3),s.setHours(0,0,0,0),s}static endOfWeek(e,t=0){const s=x.startOfWeek(e,t);return s.setTime(s.getTime()+6*24*60*60*1e3),s.setHours(23,59,59,999),s}static startOfMonth(e){return new Date(e.getFullYear(),e.getMonth(),1,0,0,0,0)}static endOfMonth(e){return new Date(e.getFullYear(),e.getMonth()+1,0,23,59,59,999)}static startOfYear(e){return new Date(e.getFullYear(),0,1,0,0,0,0)}static endOfYear(e){return new Date(e.getFullYear(),11,31,23,59,59,999)}static addDays(e,t){const s=new Date(e);return s.setTime(s.getTime()+t*24*60*60*1e3),s}static addWeeks(e,t){return x.addDays(e,t*7)}static addMonths(e,t){const s=new Date(e),i=s.getDate();return s.setMonth(s.getMonth()+t),s.getDate()!==i&&s.setDate(0),s}static addYears(e,t){const s=new Date(e);return s.setFullYear(s.getFullYear()+t),s}static getUTCDateString(e){const t=e.getUTCFullYear(),s=String(e.getUTCMonth()+1).padStart(2,"0"),i=String(e.getUTCDate()).padStart(2,"0");return`${t}-${s}-${i}`}static getLocalDateString(e){const t=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`${t}-${s}-${i}`}static isToday(e){const t=new Date;return e.toDateString()===t.toDateString()}static isPast(e){return e<new Date}static isFuture(e){return e>new Date}static isSameDay(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}static isSameWeek(e,t,s=0){const i=x.startOfWeek(e,s),a=x.startOfWeek(t,s);return i.toDateString()===a.toDateString()}static isSameMonth(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()}static isSameYear(e,t){return e.getFullYear()===t.getFullYear()}static differenceInDays(e,t){const s=e.getTime()-t.getTime();return Math.floor(s/(1e3*60*60*24))}static differenceInWeeks(e,t){return Math.floor(x.differenceInDays(e,t)/7)}static differenceInMonths(e,t){const s=e.getFullYear()-t.getFullYear(),i=e.getMonth()-t.getMonth();return s*12+i}static getWeekNumber(e){const t=new Date(e.getFullYear(),0,1),s=(e-t)/864e5;return Math.ceil((s+t.getDay()+1)/7)}static getDayOfWeek(e,t=0){return(e.getDay()-t+7)%7}static getDaysInMonth(e){return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()}static format(e,t="en-US",s={}){return new Intl.DateTimeFormat(t,s).format(e)}static getMonthName(e,t="en-US",s="long"){return x.format(e,t,{month:s})}static getDayName(e,t="en-US",s="long"){return x.format(e,t,{weekday:s})}static formatTime(e,t="en-US",s=!1){return x.format(e,t,{hour:"numeric",minute:"2-digit",hour12:!s})}static parseTime(e){const[t,s]=e.split(":").map(Number);return{hours:t,minutes:s}}static setTime(e,t){const s=new Date(e),{hours:i,minutes:a}=x.parseTime(t);return s.setHours(i,a,0,0),s}static isLeapYear(e){return e%4===0&&e%100!==0||e%400===0}static getDateRange(e,t){const s=[],i=new Date(e),a=t.getTime();for(;i.getTime()<=a;)s.push(new Date(i)),i.setTime(i.getTime()+24*60*60*1e3);return s}static clone(e){return new Date(e)}static isValidDate(e){return e instanceof Date&&!isNaN(e.getTime())}static toTimeZone(e,t){const i=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(e),a={};return i.forEach(n=>{n.type!=="literal"&&(a[n.type]=n.value)}),new Date(`${a.year}-${a.month}-${a.day}T${a.hour}:${a.minute}:${a.second}`)}static getTimezoneOffset(e,t){const s=new Date(e.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(e.toLocaleString("en-US",{timeZone:t}));return(s.getTime()-i.getTime())/6e4}static isDST(e,t){const s=new Date(e.getFullYear(),0,1),i=new Date(e.getFullYear(),6,1),a=x.getTimezoneOffset(s,t),n=x.getTimezoneOffset(i,t),r=x.getTimezoneOffset(e,t);return Math.max(a,n)===r}static addHoursWithDST(e,t,s){const i=new Date(e),a=x.getTimezoneOffset(e,s);i.setTime(i.getTime()+t*60*60*1e3);const n=x.getTimezoneOffset(i,s);if(a!==n){const r=(n-a)*6e4;i.setTime(i.getTime()+r)}return i}static createInTimeZone(e,t,s,i=0,a=0,n=0,r){const o=`${e}-${String(t+1).padStart(2,"0")}-${String(s).padStart(2,"0")}`,c=`${String(i).padStart(2,"0")}:${String(a).padStart(2,"0")}:${String(n).padStart(2,"0")}`,l=new Date(`${o}T${c}`),d=x.getTimezoneOffset(l,r),h=l.getTime()+d*6e4;return new Date(h)}};class H{static parse(e){if(typeof e=="object")return this.validateRule(e);const t={freq:null,interval:1,count:null,until:null,byDay:[],byWeekNo:[],byMonth:[],byMonthDay:[],byYearDay:[],bySetPos:[],byHour:[],byMinute:[],bySecond:[],wkst:"MO",exceptions:[],tzid:null},s=e.toUpperCase().split(";");for(const i of s){const[a,n]=i.split("=");switch(a){case"FREQ":t.freq=this.parseFrequency(n);break;case"INTERVAL":t.interval=parseInt(n,10),t.interval<1&&(t.interval=1);break;case"COUNT":t.count=parseInt(n,10);break;case"UNTIL":t.until=this.parseDateTime(n);break;case"BYDAY":t.byDay=this.parseByDay(n);break;case"BYWEEKNO":t.byWeekNo=this.parseIntList(n);break;case"BYMONTH":t.byMonth=this.parseIntList(n);break;case"BYMONTHDAY":t.byMonthDay=this.parseIntList(n);break;case"BYYEARDAY":t.byYearDay=this.parseIntList(n);break;case"BYSETPOS":t.bySetPos=this.parseIntList(n);break;case"BYHOUR":t.byHour=this.parseIntList(n);break;case"BYMINUTE":t.byMinute=this.parseIntList(n);break;case"BYSECOND":t.bySecond=this.parseIntList(n);break;case"WKST":t.wkst=n;break;case"EXDATE":t.exceptions=this.parseExceptionDates(n);break;case"TZID":t.tzid=n;break}}return this.validateRule(t)}static parseFrequency(e){return["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"].includes(e)?e:"DAILY"}static parseByDay(e){const t=e.split(","),s=["SU","MO","TU","WE","TH","FR","SA"],i=[];for(const a of t){const r=a.trim().toUpperCase().match(/^([+-]?\d*)([A-Z]{2})$/);if(r){const[o,c,l]=r;s.includes(l)&&i.push(c?`${c}${l}`:l)}}return i}static parseIntList(e){return e.split(",").map(t=>parseInt(t.trim(),10)).filter(t=>!isNaN(t))}static parseDateTime(e){if(e.length===8){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10);return new Date(t,s,i)}if(e.length===15&&e[8]==="T"){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(9,2),10),n=parseInt(e.substr(11,2),10),r=parseInt(e.substr(13,2),10);return new Date(t,s,i,a,n,r)}if(e.length===16&&e[8]==="T"&&e[15]==="Z"){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(9,2),10),n=parseInt(e.substr(11,2),10),r=parseInt(e.substr(13,2),10);return new Date(Date.UTC(t,s,i,a,n,r))}return new Date(e)}static parseExceptionDates(e){return e.split(",").map(s=>this.parseDateTime(s.trim()))}static validateRule(e){if(e.freq||(e.freq="DAILY"),e.count&&e.until)throw new Error("RRULE cannot have both COUNT and UNTIL");e.interval<1&&(e.interval=1);const t=(s,i,a)=>s.filter(n=>n>=i&&n<=a);return e.byMonth=t(e.byMonth||[],1,12),e.byMonthDay=t(e.byMonthDay||[],-31,31).filter(s=>s!==0),e.byYearDay=t(e.byYearDay||[],-366,366).filter(s=>s!==0),e.byWeekNo=t(e.byWeekNo||[],-53,53).filter(s=>s!==0),e.byHour=t(e.byHour||[],0,23),e.byMinute=t(e.byMinute||[],0,59),e.bySecond=t(e.bySecond||[],0,59),e}static buildRRule(e){const t=[];if(t.push(`FREQ=${e.freq}`),e.interval&&e.interval>1&&t.push(`INTERVAL=${e.interval}`),e.count?t.push(`COUNT=${e.count}`):e.until&&t.push(`UNTIL=${this.formatDateTime(e.until)}`),e.byDay&&e.byDay.length>0){const s=e.byDay.map(i=>i.nth?`${i.nth}${i.weekday}`:i.weekday).join(",");t.push(`BYDAY=${s}`)}return e.byMonth&&e.byMonth.length>0&&t.push(`BYMONTH=${e.byMonth.join(",")}`),e.byMonthDay&&e.byMonthDay.length>0&&t.push(`BYMONTHDAY=${e.byMonthDay.join(",")}`),e.byYearDay&&e.byYearDay.length>0&&t.push(`BYYEARDAY=${e.byYearDay.join(",")}`),e.byWeekNo&&e.byWeekNo.length>0&&t.push(`BYWEEKNO=${e.byWeekNo.join(",")}`),e.bySetPos&&e.bySetPos.length>0&&t.push(`BYSETPOS=${e.bySetPos.join(",")}`),e.byHour&&e.byHour.length>0&&t.push(`BYHOUR=${e.byHour.join(",")}`),e.byMinute&&e.byMinute.length>0&&t.push(`BYMINUTE=${e.byMinute.join(",")}`),e.bySecond&&e.bySecond.length>0&&t.push(`BYSECOND=${e.bySecond.join(",")}`),e.wkst&&e.wkst!=="MO"&&t.push(`WKST=${e.wkst}`),t.join(";")}static formatDateTime(e){const t=e.getUTCFullYear(),s=String(e.getUTCMonth()+1).padStart(2,"0"),i=String(e.getUTCDate()).padStart(2,"0"),a=String(e.getUTCHours()).padStart(2,"0"),n=String(e.getUTCMinutes()).padStart(2,"0"),r=String(e.getUTCSeconds()).padStart(2,"0");return`${t}${s}${i}T${a}${n}${r}Z`}static getDescription(e){const t={SECONDLY:"second",MINUTELY:"minute",HOURLY:"hour",DAILY:"day",WEEKLY:"week",MONTHLY:"month",YEARLY:"year"},s={SU:"Sunday",MO:"Monday",TU:"Tuesday",WE:"Wednesday",TH:"Thursday",FR:"Friday",SA:"Saturday"},i={1:"first",2:"second",3:"third",4:"fourth",5:"fifth","-1":"last","-2":"second to last"};let a="Every";if(e.interval>1&&(a+=` ${e.interval}`),a+=` ${t[e.freq]}`,e.interval>1&&(a+="s"),e.byDay&&e.byDay.length>0){if(e.freq==="WEEKLY"){const n=e.byDay.map(r=>s[r.weekday]).join(", ");a+=` on ${n}`}else if(e.freq==="MONTHLY"||e.freq==="YEARLY"){const n=e.byDay.map(r=>r.nth?`the ${i[r.nth]||r.nth} ${s[r.weekday]}`:s[r.weekday]).join(", ");a+=` on ${n}`}}if(e.byMonthDay&&e.byMonthDay.length>0){const n=e.byMonthDay.map(r=>r<0?`${Math.abs(r)} day(s) from the end`:`day ${r}`).join(", ");a+=` on ${n}`}if(e.byMonth&&e.byMonth.length>0){const n=["January","February","March","April","May","June","July","August","September","October","November","December"],r=e.byMonth.map(o=>n[o-1]).join(", ");a+=` in ${r}`}return e.count?a+=`, ${e.count} time${e.count>1?"s":""}`:e.until&&(a+=`, until ${e.until.toLocaleDateString()}`),a}}class U{static expandEvent(e,t,s,i=365,a=null){if(!e.recurring||!e.recurrenceRule)return[{start:e.start,end:e.end,timezone:e.timeZone}];const n=this.parseRule(e.recurrenceRule),r=[],o=e.end-e.start,c=a||e.timeZone||"UTC",l=new A;let d=new Date(e.start),h=0;n.until&&n.until<s&&(s=n.until);let b=l.getTimezoneOffset(d,c);for(;d<=s&&h<i;){if(d>=t){const D=new Date(d),k=new Date(d.getTime()+o),S=l.getTimezoneOffset(D,c);if(S!==b){const M=b-S;D.setMinutes(D.getMinutes()+M),k.setMinutes(k.getMinutes()+M)}b=S,this.isException(D,n,e.id)||r.push({start:D,end:k,recurringEventId:e.id,timezone:c,originalStart:e.start})}if(d=this.getNextOccurrence(d,n,c),h++,n.count&&h>=n.count)break}return r}static parseRule(e){return H.parse(e)}static getNextOccurrence(e,t,s="UTC"){const i=new Date(e);switch(t.freq){case"DAILY":i.setDate(i.getDate()+t.interval);break;case"WEEKLY":if(t.byDay&&t.byDay.length>0){let n=0;for(i.setDate(i.getDate()+1);!this.matchesByDay(i,t.byDay)&&n<8;)i.setDate(i.getDate()+1),n++;n>=8&&(console.warn("RecurrenceEngine: Invalid byDay rule, falling back to weekly interval"),i.setDate(i.getDate()+7*t.interval-8))}else i.setDate(i.getDate()+7*t.interval);break;case"MONTHLY":if(t.byMonthDay&&t.byMonthDay.length>0){const a=i.getMonth();i.setMonth(a+t.interval),i.setDate(t.byMonthDay[0])}else t.byDay&&t.byDay.length>0?(i.setMonth(i.getMonth()+t.interval),this.setToWeekdayOfMonth(i,t.byDay[0],t.bySetPos[0]||1)):i.setMonth(i.getMonth()+t.interval);break;case"YEARLY":t.byMonth&&t.byMonth.length>0?(i.setFullYear(i.getFullYear()+t.interval),i.setMonth(t.byMonth[0]-1)):i.setFullYear(i.getFullYear()+t.interval);break;default:i.setTime(i.getTime()+24*60*60*1e3)}return i}static matchesByDay(e,t){const s={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},i=e.getDay();return t.some(a=>{const n=a.match(/^(-?\d+)?([A-Z]{2})$/);if(n){const r=n[2];return s[r]===i}return!1})}static setToWeekdayOfMonth(e,t,s=1){const i={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},a=t.match(/^(-?\d+)?([A-Z]{2})$/),n=a?a[2]:t,r=i[n];for(e.setDate(1);e.getDay()!==r;)e.setDate(e.getDate()+1);if(s>1)e.setDate(e.getDate()+7*(s-1));else if(s===-1){const o=new Date(e);for(o.setMonth(o.getMonth()+1),o.setDate(0);o.getDay()!==r;)o.setDate(o.getDate()-1);e.setTime(o.getTime())}}static isException(e,t,s=null){if(!t.exceptions||t.exceptions.length===0)return!1;const i=e.toDateString(),a=e.getTime();return t.exceptions.some(n=>{if(typeof n=="object"&&n.date){const r=n.date instanceof Date?n.date:new Date(n.date);return n.matchTime?Math.abs(r.getTime()-a)<1e3:r.toDateString()===i}else return(n instanceof Date?n:new Date(n)).toDateString()===i})}static addExceptions(e,t,s={}){return e.exceptions||(e.exceptions=[]),(Array.isArray(t)?t:[t]).forEach(a=>{s.reason||s.matchTime?e.exceptions.push({date:a,reason:s.reason,matchTime:s.matchTime||!1}):e.exceptions.push(a)}),e}static parseDate(e){if(e.length===8){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10);return new Date(t,s,i)}else if(e.length===15||e.length===16){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(9,2),10),n=parseInt(e.substr(11,2),10),r=parseInt(e.substr(13,2),10);return e.endsWith("Z")?new Date(Date.UTC(t,s,i,a,n,r)):new Date(t,s,i,a,n,r)}return new Date(e)}static getDescription(e){typeof e=="string"&&(e=this.parseRule(e));let t="";const s=e.interval||1;switch(e.freq){case"DAILY":t=s===1?"Daily":`Every ${s} days`;break;case"WEEKLY":if(t=s===1?"Weekly":`Every ${s} weeks`,e.byDay&&e.byDay.length>0){const i=e.byDay.map(a=>this.getDayName(a)).join(", ");t+=` on ${i}`}break;case"MONTHLY":t=s===1?"Monthly":`Every ${s} months`,e.byMonthDay&&e.byMonthDay.length>0&&(t+=` on day ${e.byMonthDay.join(", ")}`);break;case"YEARLY":t=s===1?"Yearly":`Every ${s} years`;break}return e.count?t+=`, ${e.count} times`:e.until&&(t+=`, until ${e.until.toLocaleDateString()}`),t}static getDayName(e){const t={SU:"Sunday",MO:"Monday",TU:"Tuesday",WE:"Wednesday",TH:"Thursday",FR:"Friday",SA:"Saturday"},s=e.match(/^(-?\d+)?([A-Z]{2})$/),i=s?s[2]:e,a=s&&s[1]?parseInt(s[1],10):null;let n=t[i]||e;return a&&(n=`${a===-1?"Last":["","1st","2nd","3rd","4th","5th"][a]||`${a}th`} ${n}`),n}}class z{constructor(e=100){this.capacity=e,this.cache=new Map,this.hits=0,this.misses=0,this.evictions=0}get(e){if(!this.cache.has(e)){this.misses++;return}const t=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,t),this.hits++,t}put(e,t){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){const s=this.cache.keys().next().value;this.cache.delete(s),this.evictions++}this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear(),this.hits=0,this.misses=0,this.evictions=0}getStats(){const e=this.hits+this.misses>0?(this.hits/(this.hits+this.misses)*100).toFixed(2):0;return{size:this.cache.size,capacity:this.capacity,hits:this.hits,misses:this.misses,evictions:this.evictions,hitRate:`${e}%`}}keys(){return Array.from(this.cache.keys())}get size(){return this.cache.size}}class P{constructor(e={}){this.config={checkInterval:3e4,memoryThreshold:.8,criticalThreshold:.95,minCacheSize:10,maxCacheSize:1e4,adaptiveScaling:!0,...e},this.caches=new Map,this.stats={adjustments:0,emergencyClears:0,lastMemoryUsage:0,lastCheckTime:null,cacheResizes:[]},this.monitoringInterval=null,this.config.adaptiveScaling&&this.startMonitoring()}registerCache(e,t,s={}){this.caches.set(e,{cache:t,priority:s.priority||1,currentCapacity:s.initialCapacity||100,minCapacity:s.minCapacity||this.config.minCacheSize,maxCapacity:s.maxCapacity||this.config.maxCacheSize,scaleFactor:s.scaleFactor||.5,lastAccess:Date.now()})}unregisterCache(e){this.caches.delete(e)}startMonitoring(){this.monitoringInterval||(this.monitoringInterval=setInterval(()=>{this.checkMemoryPressure()},this.config.checkInterval),this.checkMemoryPressure())}stopMonitoring(){this.monitoringInterval&&(clearInterval(this.monitoringInterval),this.monitoringInterval=null)}async checkMemoryPressure(){const e=await this.getMemoryUsage();this.stats.lastMemoryUsage=e,this.stats.lastCheckTime=new Date,e>this.config.criticalThreshold?this.emergencyClear():e>this.config.memoryThreshold?this.reduceCacheSizes(e):e<this.config.memoryThreshold-.2&&this.increaseCacheSizes()}async getMemoryUsage(){if(typeof performance<"u"&&performance.memory){const e=performance.memory;if(e.jsHeapSizeLimit&&e.usedJSHeapSize)return e.usedJSHeapSize/e.jsHeapSizeLimit}if(typeof process<"u"&&typeof process.memoryUsage=="function"){const e=process.memoryUsage();return e.heapUsed/e.heapTotal}return this.estimateMemoryUsage()}estimateMemoryUsage(){let e=0,t=0;for(const[s,i]of this.caches)i.cache.size!==void 0&&(e+=i.cache.size,t+=i.maxCapacity);return t>0?e/t:.5}reduceCacheSizes(e){const t=(e-this.config.memoryThreshold)/(this.config.criticalThreshold-this.config.memoryThreshold),s=Array.from(this.caches.entries()).sort((i,a)=>i[1].priority-a[1].priority);for(const[i,a]of s){const n=Math.floor(a.currentCapacity*a.scaleFactor*t),r=Math.max(a.minCapacity,a.currentCapacity-n);r<a.currentCapacity&&this.resizeCache(i,a,r)}this.stats.adjustments++}increaseCacheSizes(){for(const[e,t]of this.caches)if(Date.now()-t.lastAccess<6e4){const i=Math.floor(t.currentCapacity*.2),a=Math.min(t.maxCapacity,t.currentCapacity+i);a>t.currentCapacity&&this.resizeCache(e,t,a)}}resizeCache(e,t,s){const i=t.currentCapacity;t.currentCapacity=s,t.cache.capacity!==void 0&&(t.cache.capacity=s),t.cache.size>s&&this.evictExcessItems(t.cache,s),this.stats.cacheResizes.push({cache:e,timestamp:new Date,oldCapacity:i,newCapacity:s,reason:s<i?"pressure":"available"}),this.stats.cacheResizes.length>100&&this.stats.cacheResizes.shift()}evictExcessItems(e,t){if(e.size<=t)return;const s=e.size-t;if(e.keys){const i=Array.from(e.keys());for(let a=0;a<s;a++)e.delete(i[a])}else e.clear&&e.clear()}emergencyClear(){for(const[e,t]of this.caches)t.cache.clear&&t.cache.clear(),t.currentCapacity=t.minCapacity;this.stats.emergencyClears++,console.warn("AdaptiveMemoryManager: Emergency cache clear triggered")}touchCache(e){const t=this.caches.get(e);t&&(t.lastAccess=Date.now())}getStats(){const e={};for(const[t,s]of this.caches)e[t]={size:s.cache.size||0,capacity:s.currentCapacity,priority:s.priority,lastAccess:new Date(s.lastAccess)};return{...this.stats,memoryUsagePercent:`${(this.stats.lastMemoryUsage*100).toFixed(2)}%`,totalCaches:this.caches.size,cacheStats:e,monitoring:this.monitoringInterval!==null}}async checkNow(){await this.checkMemoryPressure()}setThresholds(e){e.memoryThreshold!==void 0&&(this.config.memoryThreshold=Math.max(.5,Math.min(.95,e.memoryThreshold))),e.criticalThreshold!==void 0&&(this.config.criticalThreshold=Math.max(this.config.memoryThreshold+.05,Math.min(1,e.criticalThreshold)))}destroy(){this.stopMonitoring(),this.caches.clear()}}class Y{constructor(e={}){this.config={enableCache:!0,cacheCapacity:500,maxIndexDays:365,batchSize:100,enableMetrics:!0,cleanupInterval:36e5,maxIndexAge:30*24*60*60*1e3,enableAdaptiveMemory:!0,...e},this.eventCache=new z(this.config.cacheCapacity),this.queryCache=new z(Math.floor(this.config.cacheCapacity/2)),this.dateRangeCache=new z(Math.floor(this.config.cacheCapacity/4)),this.config.enableAdaptiveMemory&&(this.memoryManager=new P({checkInterval:3e4,memoryThreshold:.75,criticalThreshold:.9}),this.memoryManager.registerCache("events",this.eventCache,{priority:3,initialCapacity:this.config.cacheCapacity,minCapacity:50,maxCapacity:2e3}),this.memoryManager.registerCache("queries",this.queryCache,{priority:2,initialCapacity:Math.floor(this.config.cacheCapacity/2),minCapacity:25,maxCapacity:1e3}),this.memoryManager.registerCache("dateRanges",this.dateRangeCache,{priority:1,initialCapacity:Math.floor(this.config.cacheCapacity/4),minCapacity:10,maxCapacity:500})),this.lazyIndexes=new Map,this.pendingIndexes=new Map,this.batchQueue=[],this.batchTimer=null,this.batchCallbacks=[],this.metrics={operations:{},averageTimes:{},slowQueries:[]},this.cleanupTimer=null,this.config.cleanupInterval>0&&this.startCleanupTimer()}measure(e,t){if(!this.config.enableMetrics)return t();const s=performance.now();try{const i=t(),a=performance.now()-s;return this.recordMetric(e,a),i}catch(i){const a=performance.now()-s;throw this.recordMetric(e,a,!0),i}}async measureAsync(e,t){if(!this.config.enableMetrics)return await t();const s=performance.now();try{const i=await t(),a=performance.now()-s;return this.recordMetric(e,a),i}catch(i){const a=performance.now()-s;throw this.recordMetric(e,a,!0),i}}recordMetric(e,t,s=!1){this.metrics.operations[e]||(this.metrics.operations[e]={count:0,totalTime:0,errors:0,min:1/0,max:0});const i=this.metrics.operations[e];i.count++,i.totalTime+=t,i.min=Math.min(i.min,t),i.max=Math.max(i.max,t),s&&i.errors++,this.metrics.averageTimes[e]=i.totalTime/i.count,t>100&&(this.metrics.slowQueries.push({operation:e,duration:t,timestamp:new Date,isError:s}),this.metrics.slowQueries.length>100&&this.metrics.slowQueries.shift())}getMetrics(){const e={cacheStats:{event:this.eventCache.getStats(),query:this.queryCache.getStats(),dateRange:this.dateRangeCache.getStats()},operations:{},slowestOperations:[],recentSlowQueries:this.metrics.slowQueries.slice(-10),memoryManagement:this.memoryManager?this.memoryManager.getStats():null};for(const[t,s]of Object.entries(this.metrics.operations))e.operations[t]={count:s.count,avgTime:`${(s.totalTime/s.count).toFixed(2)}ms`,minTime:`${s.min.toFixed(2)}ms`,maxTime:`${s.max.toFixed(2)}ms`,totalTime:`${s.totalTime.toFixed(2)}ms`,errors:s.errors,errorRate:`${(s.errors/s.count*100).toFixed(2)}%`};return e.slowestOperations=Object.entries(this.metrics.averageTimes).sort((t,s)=>s[1]-t[1]).slice(0,5).map(([t,s])=>({operation:t,avgTime:`${s.toFixed(2)}ms`})),e}shouldUseLazyIndexing(e){return Math.ceil((e.end-e.start)/864e5)>this.config.maxIndexDays}createLazyIndexMarkers(e){const t={eventId:e.id,start:e.start,end:e.end,indexed:new Set,pending:!1},s=new Date(e.start.getFullYear(),e.start.getMonth(),1),i=new Date(e.end.getFullYear(),e.end.getMonth(),1);return t.indexed.add(this.getMonthKey(s)),this.getMonthKey(s)!==this.getMonthKey(i)&&t.indexed.add(this.getMonthKey(i)),this.lazyIndexes.set(e.id,t),t}async expandLazyIndex(e,t,s){const i=this.lazyIndexes.get(e);if(!i)return new Set;if(i.pending)return this.pendingIndexes.get(e);i.pending=!0;const a=new Promise(n=>{setTimeout(()=>{const r=new Set,o=new Date(t);for(;o<=s;){const c=o.toDateString();i.indexed.has(c)||(r.add(c),i.indexed.add(c)),o.setDate(o.getDate()+1)}i.pending=!1,this.pendingIndexes.delete(e),n(r)},0)});return this.pendingIndexes.set(e,a),a}getMonthKey(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`}cache(e,t,s="event"){if(!this.config.enableCache)return;let i,a;switch(s){case"event":i=this.eventCache,a="events";break;case"query":i=this.queryCache,a="queries";break;case"dateRange":i=this.dateRangeCache,a="dateRanges";break;default:return}i.put(e,t),this.memoryManager&&this.memoryManager.touchCache(a)}getFromCache(e,t="event"){if(!this.config.enableCache)return;let s,i;switch(t){case"event":s=this.eventCache.get(e),i="events";break;case"query":s=this.queryCache.get(e),i="queries";break;case"dateRange":s=this.dateRangeCache.get(e),i="dateRanges";break;default:return}return s!==void 0&&this.memoryManager&&this.memoryManager.touchCache(i),s}invalidateEventCaches(e){this.eventCache.delete(e),this.queryCache.clear(),this.dateRangeCache.clear()}batch(e){return new Promise((t,s)=>{this.batchQueue.push(e),this.batchCallbacks.push({resolve:t,reject:s}),this.batchQueue.length>=this.config.batchSize?this.processBatch():this.batchTimer||(this.batchTimer=setTimeout(()=>this.processBatch(),10))})}processBatch(){if(this.batchTimer&&(clearTimeout(this.batchTimer),this.batchTimer=null),this.batchQueue.length===0)return;const e=this.batchQueue.splice(0),t=this.batchCallbacks.splice(0),s=[],i=[];e.forEach((a,n)=>{try{s[n]=a()}catch(r){i[n]=r}}),t.forEach((a,n)=>{i[n]?a.reject(i[n]):a.resolve(s[n])})}startCleanupTimer(){this.cleanupTimer=setInterval(()=>{this.cleanupOldIndexes()},this.config.cleanupInterval)}cleanupOldIndexes(){const e=Date.now(),t=this.config.maxIndexAge;for(const[s,i]of this.lazyIndexes)i.end.getTime()<e-t&&this.lazyIndexes.delete(s);this.metrics.slowQueries.length>100&&(this.metrics.slowQueries=this.metrics.slowQueries.slice(-100))}optimizeQuery(e,t){const s=this.getFromCache(e,"query");if(s!==void 0)return s;const i=this.measure(`query:${e}`,t);return this.cache(e,i,"query"),i}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=null),this.batchTimer&&(clearTimeout(this.batchTimer),this.batchTimer=null),this.eventCache.clear(),this.queryCache.clear(),this.dateRangeCache.clear(),this.lazyIndexes.clear(),this.pendingIndexes.clear()}}class N{constructor(e){this.eventStore=e,this.conflictIdCounter=0}checkConflicts(e,t={}){const s={checkAttendees:!0,checkResources:!0,checkLocation:!0,ignoreAllDay:!1,excludeEventIds:[],includeStatuses:["confirmed","tentative"],bufferMinutes:0,...t};if(!e.start||!e.end)throw new Error("Event must have start and end dates");const i=[],a=new Set,n=new Set,r=new Date(e.start.getTime()-s.bufferMinutes*6e4),o=new Date(e.end.getTime()+s.bufferMinutes*6e4),c=this.eventStore.getEventsInRange(r,o,!1).filter(l=>!(l.id===e.id||s.excludeEventIds.includes(l.id)||!s.includeStatuses.includes(l.status)||s.ignoreAllDay&&(l.allDay||e.allDay)||l.status==="cancelled"));for(const l of c){const d=this._detectEventConflicts(e,l,s);d.length>0&&(i.push(...d),a.add(e.id),a.add(l.id),e.attendees&&e.attendees.forEach(h=>n.add(h.email)),l.attendees&&l.attendees.forEach(h=>n.add(h.email)))}return this._buildConflictSummary(i,a,n)}checkEventPairConflicts(e,t,s={}){const i={checkAttendees:!0,checkResources:!0,checkLocation:!0,bufferMinutes:0,...s};return this._detectEventConflicts(e,t,i)}getBusyPeriods(e,t,s,i={}){const a={includeStatuses:["confirmed","tentative"],mergePeriods:!0,...i},n=[];return this.eventStore.getEventsInRange(t,s,!1).filter(c=>!a.includeStatuses.includes(c.status)||c.status==="cancelled"?!1:c.attendees&&c.attendees.some(l=>e.includes(l.email))).forEach(c=>{n.push({start:c.start,end:c.end,eventIds:[c.id]})}),a.mergePeriods&&n.length>1?this._mergeBusyPeriods(n):n.sort((c,l)=>c.start-l.start)}getFreePeriods(e,t,s,i={}){const a={attendeeEmails:[],businessHoursOnly:!1,businessHours:{start:"09:00",end:"17:00"},excludeWeekends:!1,...i},n=[],r=a.attendeeEmails.length>0?this.getBusyPeriods(a.attendeeEmails,e,t):this._getAllBusyPeriods(e,t);let o=new Date(e);for(const c of r)o<c.start&&(c.start-o)/6e4>=s&&(!a.businessHoursOnly||this._isWithinBusinessHours(o,c.start,a))&&n.push({start:new Date(o),end:new Date(c.start)}),o=new Date(Math.max(o.getTime(),c.end.getTime()));return o<t&&(t-o)/6e4>=s&&(!a.businessHoursOnly||this._isWithinBusinessHours(o,t,a))&&n.push({start:new Date(o),end:new Date(t)}),n}_detectEventConflicts(e,t,s){const i=[];if(this._checkTimeOverlap(e,t,s.bufferMinutes)){const n=this._createTimeConflict(e,t);if(i.push(n),s.checkAttendees){const r=this._checkAttendeeConflicts(e,t);i.push(...r)}if(s.checkResources){const r=this._checkResourceConflicts(e,t);i.push(...r)}if(s.checkLocation){const r=this._checkLocationConflict(e,t);r&&i.push(r)}}return i}_checkTimeOverlap(e,t,s=0){const i=s*6e4,a=e.start.getTime()-i,n=e.end.getTime()+i,r=t.start.getTime(),o=t.end.getTime();return!(n<=r||o<=a)}_createTimeConflict(e,t){const s=new Date(Math.max(e.start.getTime(),t.start.getTime())),i=new Date(Math.min(e.end.getTime(),t.end.getTime())),a=(i-s)/6e4;let n="low";return a>=60?n="high":a>=30&&(n="medium"),e.status==="confirmed"&&t.status==="confirmed"&&(n=n==="low"?"medium":n==="medium"?"high":"critical"),{id:`conflict_${++this.conflictIdCounter}`,type:"time",severity:n,eventId:e.id,conflictingEventId:t.id,description:`Time overlap: ${e.title} conflicts with ${t.title}`,overlapStart:s,overlapEnd:i,overlapMinutes:a,metadata:{event1Title:e.title,event2Title:t.title,event1Status:e.status,event2Status:t.status}}}_checkAttendeeConflicts(e,t){const s=[];if(!e.attendees||!t.attendees)return s;const i=[];for(const a of e.attendees)for(const n of t.attendees)a.email===n.email&&i.push(a.email);if(i.length>0){let a="medium";i.some(r=>{const o=e.attendees.find(l=>l.email===r),c=t.attendees.find(l=>l.email===r);return(o==null?void 0:o.responseStatus)==="accepted"&&(c==null?void 0:c.responseStatus)==="accepted"})&&(a="critical"),s.push({id:`conflict_${++this.conflictIdCounter}`,type:"attendee",severity:a,eventId:e.id,conflictingEventId:t.id,description:`Attendee conflict: ${i.length} attendee(s) double-booked`,conflictingAttendees:i,metadata:{attendeeCount:i.length,attendeeEmails:i}})}return s}_checkResourceConflicts(e,t){var n,r;const s=[],i=((n=e.attendees)==null?void 0:n.filter(o=>o.resource))||[],a=((r=t.attendees)==null?void 0:r.filter(o=>o.resource))||[];for(const o of i)for(const c of a)o.email===c.email&&s.push({id:`conflict_${++this.conflictIdCounter}`,type:"resource",severity:"critical",eventId:e.id,conflictingEventId:t.id,description:`Resource conflict: ${o.name} is double-booked`,conflictingResource:o.email,metadata:{resourceName:o.name,resourceEmail:o.email}});return s}_checkLocationConflict(e,t){if(!e.location||!t.location)return null;const s=e.location.trim().toLowerCase(),i=t.location.trim().toLowerCase();return s===i?{id:`conflict_${++this.conflictIdCounter}`,type:"location",severity:"high",eventId:e.id,conflictingEventId:t.id,description:`Location conflict: ${e.location} is double-booked`,metadata:{location:e.location}}:null}_buildConflictSummary(e,t,s){const i={},a={};for(const n of e)i[n.type]=(i[n.type]||0)+1,a[n.severity]=(a[n.severity]||0)+1;return{hasConflicts:e.length>0,totalConflicts:e.length,conflicts:e,conflictsByType:i,conflictsBySeverity:a,affectedEventIds:Array.from(t),affectedAttendees:Array.from(s)}}_mergeBusyPeriods(e){if(e.length<=1)return e;e.sort((s,i)=>s.start-i.start);const t=[e[0]];for(let s=1;s<e.length;s++){const i=e[s],a=t[t.length-1];i.start<=a.end?(a.end=new Date(Math.max(a.end.getTime(),i.end.getTime())),a.eventIds.push(...i.eventIds)):t.push(i)}return t}_getAllBusyPeriods(e,t){return this.eventStore.getEventsInRange(e,t,!1).filter(i=>i.status!=="cancelled").map(i=>({start:i.start,end:i.end,eventIds:[i.id]})).sort((i,a)=>i.start-a.start)}_isWithinBusinessHours(e,t,s){const i=e.getHours(),a=t.getHours(),n=parseInt(s.businessHours.start.split(":")[0]),r=parseInt(s.businessHours.end.split(":")[0]);return i>=n&&a<=r}}class V{constructor(e={}){this.events=new Map,this.indices={byDate:new Map,byMonth:new Map,recurring:new Set,byCategory:new Map,byStatus:new Map},this.timezoneManager=new A,this.defaultTimezone=e.timezone||this.timezoneManager.getSystemTimezone(),this.optimizer=new Y(e.performance),this.conflictDetector=new N(this),this.isBatchMode=!1,this.batchNotifications=[],this.batchBackup=null,this.version=0,this.listeners=new Set}addEvent(e){return this.optimizer.measure("addEvent",()=>{if(e instanceof E||(e=new E(e)),this.events.has(e.id))throw new Error(`Event with id ${e.id} already exists`);return this.events.set(e.id,e),this.optimizer.cache(e.id,e,"event"),this._indexEvent(e),this.isBatchMode?this.batchNotifications.push({type:"add",event:e,version:++this.version}):this._notifyChange({type:"add",event:e,version:++this.version}),e})}updateEvent(e,t){const s=this.events.get(e);if(!s)throw new Error(`Event with id ${e} not found`);this._unindexEvent(s);const i=s.clone(t);return this.events.set(e,i),this._indexEvent(i),this._notifyChange({type:"update",event:i,oldEvent:s,version:++this.version}),i}removeEvent(e){const t=this.events.get(e);return t?(this.events.delete(e),this._unindexEvent(t),this._notifyChange({type:"remove",event:t,version:++this.version}),!0):!1}getEvent(e){const t=this.optimizer.getFromCache(e,"event");if(t)return t;const s=this.events.get(e)||null;return s&&this.optimizer.cache(e,s,"event"),s}getAllEvents(){return Array.from(this.events.values())}queryEvents(e={}){let t=Array.from(this.events.values());if(e.start||e.end){const s=e.start?new Date(e.start):null,i=e.end?new Date(e.end):null;t=t.filter(a=>!(s&&a.end<s||i&&a.start>i))}if(e.date){const s=new Date(e.date);t=t.filter(i=>i.occursOn(s))}if(e.month&&e.year){const s=`${e.year}-${String(e.month).padStart(2,"0")}`,i=this.indices.byMonth.get(s)||new Set;t=t.filter(a=>i.has(a.id))}return e.hasOwnProperty("allDay")&&(t=t.filter(s=>s.allDay===e.allDay)),e.hasOwnProperty("recurring")&&(t=t.filter(s=>s.recurring===e.recurring)),e.status&&(t=t.filter(s=>s.status===e.status)),e.categories&&e.categories.length>0&&(t=t.filter(s=>e.matchAllCategories?s.hasAllCategories(e.categories):s.hasAnyCategory(e.categories))),e.hasOwnProperty("hasAttendees")&&(t=t.filter(s=>e.hasAttendees?s.hasAttendees:!s.hasAttendees)),e.organizerEmail&&(t=t.filter(s=>s.organizer&&s.organizer.email===e.organizerEmail)),e.sort&&t.sort((s,i)=>{switch(e.sort){case"start":return s.start-i.start;case"end":return s.end-i.end;case"duration":return s.duration-i.duration;case"title":return s.title.localeCompare(i.title);default:return 0}}),t}getEventsForDate(e,t=null){t=t||this.defaultTimezone,f.getLocalDateString(e);const s=new Set,i=new Date(e);for(let l=-1;l<=1;l++){const d=new Date(i);d.setDate(d.getDate()+l);const h=f.getLocalDateString(d),b=this.indices.byDate.get(h);b&&b.forEach(D=>s.add(D))}const a=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`,n=this.indices.byMonth.get(a);n&&n.forEach(l=>s.add(l));const r=[],o=new Date(e);o.setHours(0,0,0,0);const c=new Date(e);c.setHours(23,59,59,999);for(const l of s){const d=this.events.get(l);if(d){const h=d.getStartInTimezone(t),b=d.getEndInTimezone(t);h<=c&&b>=o&&r.push(d)}}return r.sort((l,d)=>{const h=l.getStartInTimezone(t),b=d.getStartInTimezone(t),D=h-b;return D!==0?D:d.duration-l.duration})}getOverlappingEvents(e,t,s=null){const i=[],a=f.startOfDay(e),n=f.endOfDay(t),r=f.getDateRange(a,n),o=new Set;return r.forEach(c=>{const l=c.toDateString();(this.indices.byDate.get(l)||new Set).forEach(h=>{if(!o.has(h)&&h!==s){o.add(h);const b=this.events.get(h);b&&b.overlaps({start:e,end:t})&&i.push(b)}})}),i.sort((c,l)=>c.start-l.start)}hasConflicts(e,t,s=null){return this.getOverlappingEvents(e,t,s).length>0}getOverlapGroups(e,t=!0){let s=this.getEventsForDate(e);t&&(s=s.filter(n=>!n.allDay));const i=[],a=new Set;return s.forEach(n=>{if(a.has(n.id))return;const r=[n];a.add(n.id);let o=0;for(;o<r.length;){const c=r[o];s.forEach(l=>{!a.has(l.id)&&c.overlaps(l)&&(r.push(l),a.add(l.id))}),o++}i.push(r)}),i}calculateEventPositions(e){const t=new Map;if(e.length===0)return t;e.sort((a,n)=>{const r=a.start-n.start;return r!==0?r:n.end-n.start-(a.end-a.start)});const s=[];e.forEach(a=>{let n=0;for(;n<s.length&&s[n].some(c=>c.overlaps(a));)n++;s[n]||(s[n]=[]),s[n].push(a),t.set(a.id,{column:n,totalColumns:0})});const i=s.length;return t.forEach(a=>{a.totalColumns=i}),t}getEventsInRange(e,t,s=!0,i=null){typeof s=="string"&&(i=s,s=!0),i=i||this.defaultTimezone;const a=this.timezoneManager.toUTC(e,i),n=this.timezoneManager.toUTC(t,i),r=this.queryEvents({start:a,end:n,sort:"start"});if(!s)return r;const o=[];return r.forEach(c=>{if(c.recurring&&c.recurrenceRule){const l=this.expandRecurringEvent(c,e,t,i);o.push(...l)}else o.push(c)}),o.sort((c,l)=>{const d=c.getStartInTimezone(i),h=l.getStartInTimezone(i);return d-h})}expandRecurringEvent(e,t,s,i=null){if(!e.recurring||!e.recurrenceRule)return[e];i=i||this.defaultTimezone;const a=e.timeZone||i;return U.expandEvent(e,t,s).map((r,o)=>e.clone({id:`${e.id}_occurrence_${o}`,start:r.start,end:r.end,timeZone:a,metadata:{...e.metadata,recurringEventId:e.id,occurrenceIndex:o}}))}clear(){const e=this.getAllEvents();this.events.clear(),this.indices.byDate.clear(),this.indices.byMonth.clear(),this.indices.recurring.clear(),this._notifyChange({type:"clear",oldEvents:e,version:++this.version})}loadEvents(e){this.clear();for(const t of e)this.addEvent(t)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}_indexEvent(e){if(this.optimizer.shouldUseLazyIndexing(e)){this._indexEventLazy(e);return}const t=e.getStartInTimezone(e.timeZone),s=e.getEndInTimezone(e.endTimeZone||e.timeZone),i=f.startOfDay(t),a=f.endOfDay(s);f.getDateRange(i,a).forEach(o=>{const c=f.getLocalDateString(o);this.indices.byDate.has(c)||this.indices.byDate.set(c,new Set),this.indices.byDate.get(c).add(e.id)}),`${i.getFullYear()}${String(i.getMonth()+1).padStart(2,"0")}`,`${a.getFullYear()}${String(a.getMonth()+1).padStart(2,"0")}`;const r=new Date(i.getFullYear(),i.getMonth(),1);for(;r<=a;){const o=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}`;this.indices.byMonth.has(o)||this.indices.byMonth.set(o,new Set),this.indices.byMonth.get(o).add(e.id),r.setMonth(r.getMonth()+1)}e.categories&&e.categories.length>0&&e.categories.forEach(o=>{this.indices.byCategory.has(o)||this.indices.byCategory.set(o,new Set),this.indices.byCategory.get(o).add(e.id)}),e.status&&(this.indices.byStatus.has(e.status)||this.indices.byStatus.set(e.status,new Set),this.indices.byStatus.get(e.status).add(e.id)),e.recurring&&this.indices.recurring.add(e.id)}_indexEventLazy(e){this.optimizer.createLazyIndexMarkers(e);const t=e.getStartInTimezone(e.timeZone),s=e.getEndInTimezone(e.endTimeZone||e.timeZone),i=f.startOfDay(t),a=f.endOfDay(s),n=new Date(i);if(n.setDate(n.getDate()+7),f.getDateRange(i,n<a?n:a).forEach(c=>{const l=f.getLocalDateString(c);this.indices.byDate.has(l)||this.indices.byDate.set(l,new Set),this.indices.byDate.get(l).add(e.id)}),a>n){const c=new Date(a);c.setDate(c.getDate()-7),f.getDateRange(c>i?c:i,a).forEach(d=>{const h=f.getLocalDateString(d);this.indices.byDate.has(h)||this.indices.byDate.set(h,new Set),this.indices.byDate.get(h).add(e.id)})}const o=new Date(i.getFullYear(),i.getMonth(),1);for(;o<=a;){const c=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}`;this.indices.byMonth.has(c)||this.indices.byMonth.set(c,new Set),this.indices.byMonth.get(c).add(e.id),o.setMonth(o.getMonth()+1)}e.categories&&e.categories.length>0&&e.categories.forEach(c=>{this.indices.byCategory.has(c)||this.indices.byCategory.set(c,new Set),this.indices.byCategory.get(c).add(e.id)}),e.status&&(this.indices.byStatus.has(e.status)||this.indices.byStatus.set(e.status,new Set),this.indices.byStatus.get(e.status).add(e.id)),e.recurring&&this.indices.recurring.add(e.id)}_unindexEvent(e){for(const[t,s]of this.indices.byDate)s.delete(e.id),s.size===0&&this.indices.byDate.delete(t);for(const[t,s]of this.indices.byMonth)s.delete(e.id),s.size===0&&this.indices.byMonth.delete(t);this.indices.recurring.delete(e.id)}_notifyChange(e){for(const t of this.listeners)try{t(e)}catch(s){console.error("Error in EventStore listener:",s)}}getStats(){return{totalEvents:this.events.size,recurringEvents:this.indices.recurring.size,indexedDates:this.indices.byDate.size,indexedMonths:this.indices.byMonth.size,indexedCategories:this.indices.byCategory.size,indexedStatuses:this.indices.byStatus.size,version:this.version,performanceMetrics:this.optimizer.getMetrics()}}startBatch(e=!1){this.isBatchMode=!0,this.batchNotifications=[],e&&(this.batchBackup={events:new Map(this.events),indices:{byDate:new Map(Array.from(this.indices.byDate.entries()).map(([t,s])=>[t,new Set(s)])),byMonth:new Map(Array.from(this.indices.byMonth.entries()).map(([t,s])=>[t,new Set(s)])),recurring:new Set(this.indices.recurring),byCategory:new Map(Array.from(this.indices.byCategory.entries()).map(([t,s])=>[t,new Set(s)])),byStatus:new Map(Array.from(this.indices.byStatus.entries()).map(([t,s])=>[t,new Set(s)]))},version:this.version})}commitBatch(){this.isBatchMode&&(this.isBatchMode=!1,this.batchBackup=null,this.batchNotifications.length>0&&this._notifyChange({type:"batch",changes:this.batchNotifications,count:this.batchNotifications.length,version:++this.version}),this.batchNotifications=[])}rollbackBatch(){this.isBatchMode&&(this.isBatchMode=!1,this.batchBackup&&(this.events=this.batchBackup.events,this.indices=this.batchBackup.indices,this.version=this.batchBackup.version,this.batchBackup=null,this.optimizer.clearCache()),this.batchNotifications=[])}async executeBatch(e,t=!0){this.startBatch(t);try{const s=await e();return this.commitBatch(),s}catch(s){throw t&&this.rollbackBatch(),s}}addEvents(e){return this.optimizer.measure("addEvents",()=>{this.startBatch();const t=[],s=[];for(const i of e)try{t.push(this.addEvent(i))}catch(a){s.push({event:i,error:a.message})}return this.commitBatch(),s.length>0&&console.warn(`Failed to add ${s.length} events:`,s),t})}updateEvents(e){return this.optimizer.measure("updateEvents",()=>{this.startBatch();const t=[],s=[];for(const{id:i,updates:a}of e)try{t.push(this.updateEvent(i,a))}catch(n){s.push({id:i,error:n.message})}return this.commitBatch(),s.length>0&&console.warn(`Failed to update ${s.length} events:`,s),t})}removeEvents(e){return this.optimizer.measure("removeEvents",()=>{this.startBatch();let t=0;for(const s of e)this.removeEvent(s)&&t++;return this.commitBatch(),t})}getPerformanceMetrics(){return this.optimizer.getMetrics()}clearCaches(){this.optimizer.eventCache.clear(),this.optimizer.queryCache.clear(),this.optimizer.dateRangeCache.clear()}optimizeIndices(e){e||(e=new Date,e.setMonth(e.getMonth()-6)),e.toDateString();let t=0;for(const[s,i]of this.indices.byDate)if(new Date(s)<e){let n=!1;for(const r of i){const o=this.events.get(r);if(o&&o.end>=e){n=!0;break}}n||(this.indices.byDate.delete(s),t++)}return console.log(`Optimized indices: removed ${t} old date entries`),t}destroy(){this.clear(),this.optimizer.destroy(),this.listeners.clear()}checkConflicts(e,t={}){return this.conflictDetector.checkConflicts(e,t)}checkEventPairConflicts(e,t,s={}){const i=this.getEvent(e),a=this.getEvent(t);if(!i||!a)throw new Error("One or both events not found");return this.conflictDetector.checkEventPairConflicts(i,a,s)}getAllConflicts(e,t,s={}){const i=this.getEventsInRange(e,t,!1),a=[],n=new Set;for(let r=0;r<i.length;r++)for(let o=r+1;o<i.length;o++){const c=`${i[r].id}-${i[o].id}`;if(!n.has(c)){n.add(c);const l=this.conflictDetector.checkEventPairConflicts(i[r],i[o],s);a.push(...l)}}return this.conflictDetector._buildConflictSummary(a,new Set(i.map(r=>r.id)),new Set)}getBusyPeriods(e,t,s,i={}){return this.conflictDetector.getBusyPeriods(e,t,s,i)}getFreePeriods(e,t,s,i={}){return this.conflictDetector.getFreePeriods(e,t,s,i)}addEventWithConflictCheck(e,t=!0){const s=this.checkConflicts(e);if(!t&&s.hasConflicts)throw new Error(`Cannot add event: ${s.totalConflicts} conflicts detected`);return{event:this.addEvent(e),conflicts:s}}findEventsWithConflicts(e={}){const t=[],s=this.getAllEvents();for(const i of s){const a=this.checkConflicts(i,e);a.hasConflicts&&t.push({event:i,conflicts:a.conflicts})}return t}}let W=class{constructor(e={}){this.state={view:"month",currentDate:new Date,selectedEventId:null,selectedDate:null,hoveredEventId:null,hoveredDate:null,weekStartsOn:0,showWeekNumbers:!1,showWeekends:!0,fixedWeekCount:!0,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,locale:"en-US",hourFormat:"12h",businessHours:{start:"09:00",end:"17:00"},filters:{searchTerm:"",categories:[],showAllDay:!0,showTimed:!0},isDragging:!1,isResizing:!1,isCreating:!1,isLoading:!1,loadingMessage:"",error:null,metadata:{},...e},this.listeners=new Map,this.globalListeners=new Set,this.history=[],this.historyIndex=-1,this.maxHistorySize=50}getState(){return Object.freeze({...this.state})}get(e){return this.state[e]}setState(e){const t=this.state;typeof e=="function"&&(e=e(t));const s={...t,...e,filters:e.filters?{...t.filters,...e.filters}:t.filters,businessHours:e.businessHours?{...t.businessHours,...e.businessHours}:t.businessHours,metadata:e.metadata?{...t.metadata,...e.metadata}:t.metadata};this._hasChanged(t,s)&&(this.state=s,this._addToHistory(s),this._notifyListeners(t,s))}setView(e){const t=["month","week","day","list"];if(!t.includes(e))throw new Error(`Invalid view: ${e}. Must be one of: ${t.join(", ")}`);this.setState({view:e})}setCurrentDate(e){if(e instanceof Date||(e=new Date(e)),isNaN(e.getTime()))throw new Error("Invalid date");this.setState({currentDate:e})}navigateNext(){const{view:e,currentDate:t}=this.state,s=new Date(t);switch(e){case"month":s.setMonth(s.getMonth()+1);break;case"week":s.setDate(s.getDate()+7);break;case"day":s.setDate(s.getDate()+1);break}this.setCurrentDate(s)}navigatePrevious(){const{view:e,currentDate:t}=this.state,s=new Date(t);switch(e){case"month":s.setMonth(s.getMonth()-1);break;case"week":s.setDate(s.getDate()-7);break;case"day":s.setDate(s.getDate()-1);break}this.setCurrentDate(s)}navigateToday(){this.setCurrentDate(new Date)}selectEvent(e){this.setState({selectedEventId:e})}clearEventSelection(){this.setState({selectedEventId:null})}selectDate(e){e instanceof Date||(e=new Date(e)),this.setState({selectedDate:e})}clearDateSelection(){this.setState({selectedDate:null})}setLoading(e,t=""){this.setState({isLoading:e,loadingMessage:t})}setError(e){this.setState({error:e?e instanceof Error?e.message:e:null})}updateFilters(e){this.setState({filters:{...this.state.filters,...e}})}subscribe(e){return this.globalListeners.add(e),()=>{this.globalListeners.delete(e)}}watch(e,t){const s=Array.isArray(e)?e:[e];return s.forEach(i=>{this.listeners.has(i)||this.listeners.set(i,new Set),this.listeners.get(i).add(t)}),()=>{s.forEach(i=>{const a=this.listeners.get(i);a&&(a.delete(t),a.size===0&&this.listeners.delete(i))})}}canUndo(){return this.historyIndex>0}canRedo(){return this.historyIndex<this.history.length-1}getUndoCount(){return this.historyIndex}getRedoCount(){return this.history.length-1-this.historyIndex}undo(){if(!this.canUndo())return!1;this.historyIndex--;const e=this.history[this.historyIndex],t=this.state;return this.state={...e},this._notifyListeners(t,this.state),!0}redo(){if(!this.canRedo())return!1;this.historyIndex++;const e=this.history[this.historyIndex],t=this.state;return this.state={...e},this._notifyListeners(t,this.state),!0}reset(){const e=this.history[0]||{};this.setState(e),this.history=[e],this.historyIndex=0}_hasChanged(e,t){return!this._deepEqual(e,t)}_deepEqual(e,t,s=new Set){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(typeof e!="object")return e===t;if(s.has(e)||s.has(t))return!1;if(s.add(e),s.add(t),Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return s.delete(e),s.delete(t),!1;for(let n=0;n<e.length;n++)if(!this._deepEqual(e[n],t[n],s))return s.delete(e),s.delete(t),!1;return s.delete(e),s.delete(t),!0}if(e instanceof Date&&t instanceof Date){const n=e.getTime()===t.getTime();return s.delete(e),s.delete(t),n}const i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return s.delete(e),s.delete(t),!1;i.sort(),a.sort();for(let n=0;n<i.length;n++)if(i[n]!==a[n])return s.delete(e),s.delete(t),!1;for(const n of i)if(!this._deepEqual(e[n],t[n],s))return s.delete(e),s.delete(t),!1;return s.delete(e),s.delete(t),!0}_addToHistory(e){this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push({...e}),this.historyIndex++,this.history.length>this.maxHistorySize&&(this.history.shift(),this.historyIndex--)}_notifyListeners(e,t){for(const s of this.globalListeners)try{s(t,e)}catch(i){console.error("Error in state listener:",i)}for(const[s,i]of this.listeners)if(e[s]!==t[s])for(const a of i)try{a(t[s],e[s],t,e)}catch(n){console.error(`Error in state listener for key "${s}":`,n)}}};class j{constructor(e={}){this.timezoneManager=new A,this.config={view:"month",date:new Date,weekStartsOn:0,locale:"en-US",timeZone:e.timeZone||this.timezoneManager.getSystemTimezone(),showWeekNumbers:!1,showWeekends:!0,fixedWeekCount:!0,businessHours:{start:"09:00",end:"17:00"},...e},this.eventStore=new V({timezone:this.config.timeZone}),this.state=new W({view:this.config.view,currentDate:this.config.date,weekStartsOn:this.config.weekStartsOn,locale:this.config.locale,timeZone:this.config.timeZone,showWeekNumbers:this.config.showWeekNumbers,showWeekends:this.config.showWeekends,fixedWeekCount:this.config.fixedWeekCount,businessHours:this.config.businessHours}),this.listeners=new Map,this.plugins=new Set,this.views=new Map,this._setupInternalListeners(),e.events&&this.setEvents(e.events)}setView(e,t=null){this.state.setView(e),t&&this.state.setCurrentDate(t),this._emit("viewChange",{view:e,date:t||this.state.get("currentDate")})}getView(){return this.state.get("view")}next(){this.state.navigateNext(),this._emit("navigate",{direction:"next",date:this.state.get("currentDate"),view:this.state.get("view")})}previous(){this.state.navigatePrevious(),this._emit("navigate",{direction:"previous",date:this.state.get("currentDate"),view:this.state.get("view")})}today(){this.state.navigateToday(),this._emit("navigate",{direction:"today",date:this.state.get("currentDate"),view:this.state.get("view")})}goToDate(e){this.state.setCurrentDate(e),this._emit("navigate",{direction:"goto",date:e,view:this.state.get("view")})}setDate(e){this.goToDate(e)}getCurrentDate(){return new Date(this.state.get("currentDate"))}addEvent(e){!(e instanceof E)&&!e.timeZone&&(e={...e,timeZone:this.config.timeZone});const t=this.eventStore.addEvent(e);return this._emit("eventAdd",{event:t}),t}updateEvent(e,t){const s=this.eventStore.getEvent(e),i=this.eventStore.updateEvent(e,t);return this._emit("eventUpdate",{event:i,oldEvent:s}),i}removeEvent(e){const t=this.eventStore.getEvent(e),s=this.eventStore.removeEvent(e);return s&&this._emit("eventRemove",{event:t}),s}deleteEvent(e){return this.removeEvent(e)}getEvent(e){return this.eventStore.getEvent(e)}getEvents(){return this.eventStore.getAllEvents()}setEvents(e){this.eventStore.loadEvents(e),this._emit("eventsSet",{events:this.getEvents()})}queryEvents(e){return this.eventStore.queryEvents(e)}getEventsForDate(e,t=null){return this.eventStore.getEventsForDate(e,t||this.config.timeZone)}getEventsInRange(e,t,s=null){return this.eventStore.getEventsInRange(e,t,!0,s||this.config.timeZone)}setTimezone(e){const t=this.timezoneManager.parseTimezone(e),s=this.config.timeZone;this.config.timeZone=t,this.eventStore.defaultTimezone=t,this.state.setState({timeZone:t}),this._emit("timezoneChange",{timezone:t,previousTimezone:s})}getTimezone(){return this.config.timeZone}setLocale(e){this.config.locale=e,this.state.setState({locale:e}),this._emit("localeChange",{locale:e})}setWeekStartsOn(e){this.config.weekStartsOn=e,this.state.setState({weekStartsOn:e}),this._emit("weekStartsOnChange",{weekStartsOn:e})}convertTimezone(e,t,s){return this.timezoneManager.convertTimezone(e,t,s)}toCalendarTimezone(e,t){return this.timezoneManager.convertTimezone(e,t,this.config.timeZone)}fromCalendarTimezone(e,t){return this.timezoneManager.convertTimezone(e,this.config.timeZone,t)}formatInTimezone(e,t=null,s={}){return this.timezoneManager.formatInTimezone(e,t||this.config.timeZone,s)}getTimezones(){return this.timezoneManager.getCommonTimezones()}getOverlapGroups(e,t=!0){return this.eventStore.getOverlapGroups(e,t)}calculateEventPositions(e){return this.eventStore.calculateEventPositions(e)}getViewData(){const e=this.state.get("view"),t=this.state.get("currentDate");switch(e){case"month":return this._getMonthViewData(t);case"week":return this._getWeekViewData(t);case"day":return this._getDayViewData(t);case"list":return this._getListViewData(t);default:return null}}_getMonthViewData(e){const t=e.getFullYear(),s=e.getMonth(),i=this.state.get("weekStartsOn"),a=this.state.get("fixedWeekCount"),n=new Date(t,s,1),r=new Date(t,s+1,0),o=f.startOfWeek(n,i),c=[];let l=new Date(o);const d=a?6:Math.ceil((r.getDate()+f.getDayOfWeek(n,i))/7);for(let h=0;h<d;h++){const b={weekNumber:f.getWeekNumber(l),days:[]};for(let D=0;D<7;D++){const k=new Date(l),S=k.getMonth()===s,M=f.isToday(k),I=k.getDay()===0||k.getDay()===6;b.days.push({date:k,dayOfMonth:k.getDate(),isCurrentMonth:S,isToday:M,isWeekend:I,events:this.getEventsForDate(k)}),l=f.addDays(l,1)}c.push(b)}return{type:"month",year:t,month:s,monthName:f.getMonthName(e,this.state.get("locale")),weeks:c,startDate:o,endDate:new Date(l.getTime()-1)}}_getWeekViewData(e){const t=this.state.get("weekStartsOn"),s=f.startOfWeek(e,t),i=f.endOfWeek(e,t),a=[],n=new Date(s);for(let r=0;r<7;r++){const o=new Date(n);a.push({date:o,dayOfMonth:o.getDate(),dayOfWeek:o.getDay(),dayName:f.getDayName(o,this.state.get("locale")),isToday:f.isToday(o),isWeekend:o.getDay()===0||o.getDay()===6,events:this.getEventsForDate(o),overlapGroups:this.eventStore.getOverlapGroups(o,!0),getEventPositions:c=>this.eventStore.calculateEventPositions(c)}),n.setDate(n.getDate()+1)}return{type:"week",weekNumber:f.getWeekNumber(s),startDate:s,endDate:i,days:a}}_getDayViewData(e){const t=this.getEventsForDate(e),s=t.filter(n=>n.allDay),i=t.filter(n=>!n.allDay),a=[];for(let n=0;n<24;n++){const r=new Date(e);r.setHours(n,0,0,0);const o=new Date(e);o.setHours(n+1,0,0,0),a.push({hour:n,time:f.formatTime(r,this.state.get("locale")),events:i.filter(c=>c.start<o&&c.end>r)})}return{type:"day",date:e,dayName:f.getDayName(e,this.state.get("locale")),isToday:f.isToday(e),allDayEvents:s,hours:a}}_getListViewData(e){const t=new Date(e);t.setHours(0,0,0,0);const s=new Date(t);s.setDate(s.getDate()+30);const i=this.getEventsInRange(t,s),a=new Map;i.forEach(r=>{const o=r.start.toDateString();a.has(o)||a.set(o,{date:new Date(r.start),events:[]}),a.get(o).events.push(r)});const n=Array.from(a.values()).sort((r,o)=>r.date-o.date).map(r=>({...r,dayName:f.getDayName(r.date,this.state.get("locale")),isToday:f.isToday(r.date)}));return{type:"list",startDate:t,endDate:s,days:n,totalEvents:i.length}}selectEvent(e){const t=this.getEvent(e);t&&(this.state.selectEvent(e),this._emit("eventSelect",{event:t}))}clearEventSelection(){const e=this.state.get("selectedEventId");this.state.clearEventSelection(),e&&this._emit("eventDeselect",{eventId:e})}selectDate(e){this.state.selectDate(e),this._emit("dateSelect",{date:e})}clearDateSelection(){const e=this.state.get("selectedDate");this.state.clearDateSelection(),e&&this._emit("dateDeselect",{date:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}off(e,t){const s=this.listeners.get(e);s&&(s.delete(t),s.size===0&&this.listeners.delete(e))}_emit(e,t){const s=this.listeners.get(e);s&&s.forEach(i=>{try{i(t)}catch(a){console.error(`Error in event listener for "${e}":`,a)}})}_setupInternalListeners(){this.state.subscribe((e,t)=>{this._emit("stateChange",{newState:e,oldState:t})}),this.eventStore.subscribe(e=>{this._emit("eventStoreChange",e)})}use(e){if(this.plugins.has(e)){console.warn("Plugin already installed");return}if(typeof e.install=="function")e.install(this),this.plugins.add(e);else throw new Error("Plugin must have an install method")}destroy(){this.listeners.clear(),this.eventStore.clear(),this.plugins.forEach(e=>{typeof e.uninstall=="function"&&e.uninstall(this)}),this.plugins.clear(),this._emit("destroy")}}class L{constructor(){this.events=new Map,this.wildcardHandlers=new Set}on(e,t,s={}){const{once:i=!1,priority:a=0}=s;if(e.includes("*")){const o={pattern:e,handler:t,once:i,priority:a};return this.wildcardHandlers.add(o),()=>this.wildcardHandlers.delete(o)}this.events.has(e)||this.events.set(e,[]);const n={handler:t,once:i,priority:a},r=this.events.get(e);return r.push(n),r.sort((o,c)=>c.priority-o.priority),()=>{const o=r.indexOf(n);o>-1&&r.splice(o,1)}}once(e,t,s={}){return this.on(e,t,{...s,once:!0})}off(e,t){if(!this.events.has(e))return;const s=this.events.get(e),i=s.findIndex(a=>a.handler===t);i>-1&&s.splice(i,1),s.length===0&&this.events.delete(e)}async emit(e,t){const s=[];if(this.events.has(e)){const a=[...this.events.get(e)];for(const n of a){const{handler:r,once:o}=n;o&&this.off(e,r);try{const c=r(t,e);c instanceof Promise&&s.push(c)}catch(c){console.error(`Error in event handler for ${e}:`,c)}}}const i=[];for(const a of[...this.wildcardHandlers])if(this.matchesPattern(e,a.pattern)){const{handler:n,once:r}=a;r&&i.push(a);try{const o=n(t,e);o instanceof Promise&&s.push(o)}catch(o){console.error(`Error in wildcard handler for ${e}:`,o)}}return i.forEach(a=>this.wildcardHandlers.delete(a)),Promise.all(s)}matchesPattern(e,t){return new RegExp("^"+t.replace(/\*/g,".*")+"$").test(e)}clear(){this.events.clear(),this.wildcardHandlers.clear()}getEventNames(){return Array.from(this.events.keys())}getHandlerCount(e){return this.events.has(e)?this.events.get(e).length:0}}const m=new L;class F{constructor(e={}){this.calendar=new j({view:e.view||"month",date:e.date||new Date,weekStartsOn:e.weekStartsOn??0,locale:e.locale||"en-US",timeZone:e.timeZone||Intl.DateTimeFormat().resolvedOptions().timeZone,...e}),this.state={view:this.calendar.getView(),currentDate:this.calendar.getCurrentDate(),events:[],selectedEvent:null,selectedDate:null,loading:!1,error:null,config:{...e}},this.subscribers=new Set,this.subscribe=this.subscribe.bind(this),this.unsubscribe=this.unsubscribe.bind(this),this.setState=this.setState.bind(this)}getState(){return{...this.state}}setState(e,t={}){const{silent:s=!1}=t,i={...this.state};return this.state={...this.state,...e},s||(this.notifySubscribers(i,this.state),this.emitStateChange(i,this.state)),this.state}subscribe(e){return this.subscribers.add(e),()=>this.unsubscribe(e)}unsubscribe(e){this.subscribers.delete(e)}notifySubscribers(e,t){this.subscribers.forEach(s=>{try{s(t,e)}catch(i){console.error("Error in state subscriber:",i)}})}emitStateChange(e,t){const s=Object.keys(t).filter(i=>e[i]!==t[i]);s.forEach(i=>{m.emit(`state:${i}:changed`,{oldValue:e[i],newValue:t[i],state:t})}),s.length>0&&m.emit("state:changed",{oldState:e,newState:t,changedKeys:s})}setView(e){this.calendar.setView(e),this.setState({view:e}),m.emit("view:changed",{view:e})}getView(){return this.state.view}setDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("date:changed",{date:this.state.currentDate})}getCurrentDate(){return this.state.currentDate}next(){this.calendar.next(),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:next",{date:this.state.currentDate})}previous(){this.calendar.previous(),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:previous",{date:this.state.currentDate})}today(){this.calendar.today(),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:today",{date:this.state.currentDate})}goToDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:goto",{date:this.state.currentDate})}addEvent(e){const t=this.calendar.addEvent(e);if(!t)return console.error("Failed to add event to calendar"),m.emit("event:error",{action:"add",event:e,error:"Failed to add event"}),null;const s=[...this.state.events,t];return this.setState({events:s}),m.emit("event:added",{event:t}),t}updateEvent(e,t){const s=this.calendar.updateEvent(e,t);if(!s)return console.error(`Failed to update event: ${e}`),m.emit("event:error",{action:"update",eventId:e,updates:t,error:"Event not found in calendar"}),null;const i=this.state.events.findIndex(n=>n.id===e);if(i===-1)return console.error(`Event ${e} not found in state`),m.emit("event:error",{action:"update",eventId:e,error:"Event not found in state"}),null;const a=[...this.state.events];return a[i]=s,this.setState({events:a}),m.emit("event:updated",{event:s}),s}deleteEvent(e){if(!this.calendar.removeEvent(e))return console.error(`Failed to delete event: ${e}`),m.emit("event:error",{action:"delete",eventId:e,error:"Event not found"}),!1;const s=this.state.events.filter(i=>i.id!==e);return this.setState({events:s}),m.emit("event:deleted",{eventId:e}),!0}getEvents(){return this.calendar.getEvents()}getEventsForDate(e){return this.calendar.getEventsForDate(e)}getEventsInRange(e,t){return this.calendar.getEventsInRange(e,t)}getViewData(){const e=this.calendar.getViewData();return this.enrichViewData(e)}enrichViewData(e){var s;const t=(s=this.state.selectedDate)==null?void 0:s.toDateString();if(e.weeks&&(e.weeks=e.weeks.map(i=>({...i,days:i.days.map(a=>{const n=new Date(a.date);return{...a,isSelected:n.toDateString()===t,events:a.events||this.getEventsForDate(n)}})}))),e.days&&(e.days=e.days.map(i=>{const a=new Date(i.date);return{...i,isSelected:a.toDateString()===t,events:i.events||this.getEventsForDate(a)}})),e.date&&!e.days&&!e.weeks){const i=new Date(e.date);e.isSelected=i.toDateString()===t,e.events=e.events||this.getEventsForDate(i)}return e}selectEvent(e){this.setState({selectedEvent:e}),m.emit("event:selected",{event:e})}selectEventById(e){const t=this.state.events.find(s=>s.id===e);t&&this.selectEvent(t)}deselectEvent(){this.setState({selectedEvent:null}),m.emit("event:deselected",{})}selectDate(e){this.setState({selectedDate:e}),m.emit("date:selected",{date:e})}deselectDate(){this.setState({selectedDate:null}),m.emit("date:deselected",{})}isToday(e){const t=new Date;return e.toDateString()===t.toDateString()}isSelectedDate(e){return this.state.selectedDate&&e.toDateString()===this.state.selectedDate.toDateString()}isWeekend(e){const t=e.getDay();return t===0||t===6}setLoading(e){this.setState({loading:e})}setError(e){this.setState({error:e}),e&&m.emit("error",{error:e})}clearError(){this.setState({error:null})}updateConfig(e){this.setState({config:{...this.state.config,...e}}),e.weekStartsOn!==void 0&&this.calendar.setWeekStartsOn(e.weekStartsOn),e.locale!==void 0&&this.calendar.setLocale(e.locale),e.timeZone!==void 0&&this.calendar.setTimezone(e.timeZone)}destroy(){this.subscribers.clear(),this.state=null,this.calendar=null}}class y extends f{static formatDate(e,t="default",s="en-US"){if(!e)return"";const i={default:{year:"numeric",month:"long",day:"numeric"},short:{year:"numeric",month:"short",day:"numeric"},long:{weekday:"long",year:"numeric",month:"long",day:"numeric"},month:{year:"numeric",month:"long"},monthShort:{year:"numeric",month:"short"},day:{weekday:"long",day:"numeric"},dayShort:{weekday:"short",day:"numeric"},time:{hour:"numeric",minute:"2-digit"},timeShort:{hour:"numeric"},datetime:{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}},a=i[t]||i.default;return new Intl.DateTimeFormat(s,a).format(e)}static formatTime(e,t=!0,s=!1,i="en-US"){if(!e)return"";const a={hour:"numeric",minute:t?"2-digit":void 0,hour12:!s};return new Intl.DateTimeFormat(i,a).format(e)}static formatDateRange(e,t,s="en-US"){if(!e)return"";if(!t||this.isSameDay(e,t))return this.formatDate(e,"default",s);const i=this.isSameYear(e,t)?"short":"default";return`${this.formatDate(e,i,s)} - ${this.formatDate(t,"default",s)}`}static formatTimeRange(e,t,s="en-US"){if(!e)return"";const i=this.formatTime(e,!0,!1,s);if(!t)return i;const a=this.formatTime(t,!0,!1,s);return`${i} - ${a}`}static getRelativeTime(e,t=new Date,s="en-US"){const i=new Intl.RelativeTimeFormat(s,{numeric:"auto"}),a=e-t,n=Math.floor(a/1e3),r=Math.floor(n/60),o=Math.floor(r/60),c=Math.floor(o/24),l=Math.floor(c/7),d=Math.floor(c/30),h=Math.floor(c/365);return Math.abs(n)<60?i.format(n,"second"):Math.abs(r)<60?i.format(r,"minute"):Math.abs(o)<24?i.format(o,"hour"):Math.abs(c)<7?i.format(c,"day"):Math.abs(l)<4?i.format(l,"week"):Math.abs(d)<12?i.format(d,"month"):i.format(h,"year")}static isToday(e){const t=new Date;return this.isSameDay(e,t)}static isPast(e){return e<new Date}static isFuture(e){return e>new Date}static getWeekNumber(e){const t=new Date(e.getFullYear(),0,1),s=(e-t)/864e5;return Math.ceil((s+t.getDay()+1)/7)}static getDayAbbreviation(e,t="en-US"){const s=new Date(2024,0,7+e);return new Intl.DateTimeFormat(t,{weekday:"short"}).format(s)}static getMonthName(e,t="long",s="en-US"){const i=new Date(2024,e,1);return new Intl.DateTimeFormat(s,{month:t}).format(i)}static parseTimeString(e,t=new Date){const s=new Date(t),[i,a]=e.split(/\s+/),[n,r]=i.split(":").map(Number);let o=n;return a&&(a.toLowerCase()==="pm"&&n<12?o=n+12:a.toLowerCase()==="am"&&n===12&&(o=0)),s.setHours(o,r||0,0,0),s}}class T{static createElement(e,t={},s=[]){const i=document.createElement(e);return Object.entries(t).forEach(([a,n])=>{if(a==="className")i.className=n;else if(a==="style"&&typeof n=="object")Object.assign(i.style,n);else if(a.startsWith("data-"))i.setAttribute(a,n);else if(a.startsWith("on")&&typeof n=="function"){const r=a.slice(2).toLowerCase();i.addEventListener(r,n)}else i[a]=n}),s.forEach(a=>{typeof a=="string"?i.appendChild(document.createTextNode(a)):a instanceof Node&&i.appendChild(a)}),i}static addEventListeners(e,t){return Object.entries(t).forEach(([s,i])=>{e.addEventListener(s,i)}),()=>{Object.entries(t).forEach(([s,i])=>{e.removeEventListener(s,i)})}}static delegate(e,t,s,i){const a=n=>{const r=n.target.closest(t);r&&e.contains(r)&&i.call(r,n)};return e.addEventListener(s,a),()=>e.removeEventListener(s,a)}static getPosition(e){const t=e.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX,bottom:t.bottom+window.scrollY,right:t.right+window.scrollX,width:t.width,height:t.height}}static isInViewport(e,t=0){const s=e.getBoundingClientRect();return s.top>=-t&&s.left>=-t&&s.bottom<=(window.innerHeight||document.documentElement.clientHeight)+t&&s.right<=(window.innerWidth||document.documentElement.clientWidth)+t}static scrollToElement(e,t={}){const{behavior:s="smooth",block:i="start",inline:a="nearest"}=t;e.scrollIntoView({behavior:s,block:i,inline:a})}static getStyle(e,t){return window.getComputedStyle(e).getPropertyValue(t)}static setStyles(e,t){Object.assign(e.style,t)}static async animateClass(e,t,s=300){e.classList.add(t),await this.wait(s),e.classList.remove(t)}static waitForAnimation(e,t="animationend"){return new Promise(s=>{const i=()=>{e.removeEventListener(t,i),s()};e.addEventListener(t,i)})}static wait(e){return new Promise(t=>setTimeout(t,e))}static parseHTML(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}static escapeHTML(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}static debounce(e,t=250){let s;return function(...a){const n=()=>{clearTimeout(s),e(...a)};clearTimeout(s),s=setTimeout(n,t)}}static throttle(e,t=250){let s;return function(...i){s||(e.apply(this,i),s=!0,setTimeout(()=>s=!1,t))}}static closest(e,t){return e.closest(t)}static parents(e,t){const s=[];let i=e.parentElement;for(;i;)i.matches(t)&&s.push(i),i=i.parentElement;return s}static getOuterDimensions(e){const t=window.getComputedStyle(e),s={top:parseInt(t.marginTop),right:parseInt(t.marginRight),bottom:parseInt(t.marginBottom),left:parseInt(t.marginLeft)};return{width:e.offsetWidth+s.left+s.right,height:e.offsetHeight+s.top+s.bottom,margin:s}}static cloneWithEvents(e,t=!0){return e.cloneNode(t)}static trapFocus(e){const t=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(t.length===0)return e.setAttribute("tabindex","-1"),e.focus(),()=>e.removeAttribute("tabindex");const s=t[0],i=t[t.length-1],a=n=>{n.key==="Tab"&&(n.shiftKey?document.activeElement===s&&(i==null||i.focus(),n.preventDefault()):document.activeElement===i&&(s==null||s.focus(),n.preventDefault()))};return e.addEventListener("keydown",a),s==null||s.focus(),()=>e.removeEventListener("keydown",a)}}class g{static getCSSVariable(e,t=document.documentElement){return getComputedStyle(t).getPropertyValue(e).trim()}static setCSSVariables(e,t=document.documentElement){Object.entries(e).forEach(([s,i])=>{t.style.setProperty(s,i)})}static getBaseStyles(){return`
15
+ `,t=this.template();this.shadowRoot.innerHTML=e+t,this.afterRender()}template(){return""}afterRender(){}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}static get observedAttributes(){return[]}attributeChangedCallback(e,t,s){this.setProp(e,s),this._initialized&&this.render()}}class C{constructor(){this.timezones={UTC:{offset:0,dst:null},GMT:{offset:0,dst:null},"Africa/Abidjan":{offset:0,dst:null},"Africa/Accra":{offset:0,dst:null},"Africa/Addis_Ababa":{offset:180,dst:null},"Africa/Algiers":{offset:60,dst:null},"Africa/Cairo":{offset:120,dst:null},"Africa/Casablanca":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Africa/Johannesburg":{offset:120,dst:null},"Africa/Lagos":{offset:60,dst:null},"Africa/Nairobi":{offset:180,dst:null},"America/Anchorage":{offset:-540,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Argentina/Buenos_Aires":{offset:-180,dst:null},"America/Bogota":{offset:-300,dst:null},"America/Caracas":{offset:-240,dst:null},"America/Chicago":{offset:-360,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Denver":{offset:-420,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Detroit":{offset:-300,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Halifax":{offset:-240,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Los_Angeles":{offset:-480,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Mexico_City":{offset:-360,dst:{start:{month:4,week:1,day:0},end:{month:10,week:-1,day:0},offset:60}},"America/New_York":{offset:-300,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Phoenix":{offset:-420,dst:null},"America/Regina":{offset:-360,dst:null},"America/Santiago":{offset:-180,dst:{start:{month:9,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"America/Sao_Paulo":{offset:-180,dst:{start:{month:10,week:3,day:0},end:{month:2,week:3,day:0},offset:60}},"America/St_Johns":{offset:-210,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Toronto":{offset:-300,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"America/Vancouver":{offset:-480,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"Asia/Baghdad":{offset:180,dst:null},"Asia/Bangkok":{offset:420,dst:null},"Asia/Dubai":{offset:240,dst:null},"Asia/Hong_Kong":{offset:480,dst:null},"Asia/Jakarta":{offset:420,dst:null},"Asia/Jerusalem":{offset:120,dst:{start:{month:3,week:-1,day:5},end:{month:10,week:-1,day:0},offset:60}},"Asia/Karachi":{offset:300,dst:null},"Asia/Kolkata":{offset:330,dst:null},"Asia/Kuala_Lumpur":{offset:480,dst:null},"Asia/Manila":{offset:480,dst:null},"Asia/Seoul":{offset:540,dst:null},"Asia/Shanghai":{offset:480,dst:null},"Asia/Singapore":{offset:480,dst:null},"Asia/Taipei":{offset:480,dst:null},"Asia/Tehran":{offset:210,dst:{start:{month:3,week:4,day:0},end:{month:9,week:4,day:0},offset:60}},"Asia/Tokyo":{offset:540,dst:null},"Atlantic/Azores":{offset:-60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Atlantic/Bermuda":{offset:-240,dst:{start:{month:3,week:2,day:0},end:{month:11,week:1,day:0},offset:60}},"Atlantic/Reykjavik":{offset:0,dst:null},"Australia/Adelaide":{offset:570,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Australia/Brisbane":{offset:600,dst:null},"Australia/Darwin":{offset:570,dst:null},"Australia/Hobart":{offset:600,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Australia/Melbourne":{offset:600,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Australia/Perth":{offset:480,dst:null},"Australia/Sydney":{offset:600,dst:{start:{month:10,week:1,day:0},end:{month:4,week:1,day:0},offset:60}},"Europe/Amsterdam":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Athens":{offset:120,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Berlin":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Brussels":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Budapest":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Copenhagen":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Dublin":{offset:0,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Helsinki":{offset:120,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Istanbul":{offset:180,dst:null},"Europe/Kiev":{offset:120,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Lisbon":{offset:0,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/London":{offset:0,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Madrid":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Moscow":{offset:180,dst:null},"Europe/Oslo":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Paris":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Prague":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Rome":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Stockholm":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Vienna":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Warsaw":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Europe/Zurich":{offset:60,dst:{start:{month:3,week:-1,day:0},end:{month:10,week:-1,day:0},offset:60}},"Indian/Maldives":{offset:300,dst:null},"Indian/Mauritius":{offset:240,dst:null},"Pacific/Auckland":{offset:720,dst:{start:{month:9,week:-1,day:0},end:{month:4,week:1,day:0},offset:60}},"Pacific/Fiji":{offset:720,dst:{start:{month:11,week:1,day:0},end:{month:1,week:3,day:0},offset:60}},"Pacific/Guam":{offset:600,dst:null},"Pacific/Honolulu":{offset:-600,dst:null},"Pacific/Midway":{offset:-660,dst:null},"Pacific/Noumea":{offset:660,dst:null},"Pacific/Pago_Pago":{offset:-660,dst:null},"Pacific/Port_Moresby":{offset:600,dst:null},"Pacific/Tahiti":{offset:-600,dst:null}},this.aliases={EST:"America/New_York",EDT:"America/New_York",CST:"America/Chicago",CDT:"America/Chicago",MST:"America/Denver",MDT:"America/Denver",PST:"America/Los_Angeles",PDT:"America/Los_Angeles",AKST:"America/Anchorage",AKDT:"America/Anchorage",HST:"Pacific/Honolulu",AST:"America/Halifax",ADT:"America/Halifax",NST:"America/St_Johns",NDT:"America/St_Johns",BST:"Europe/London",IST:"Asia/Kolkata",WET:"Europe/Lisbon",WEST:"Europe/Lisbon",CET:"Europe/Paris",CEST:"Europe/Paris",EET:"Europe/Athens",EEST:"Europe/Athens",MSK:"Europe/Moscow",JST:"Asia/Tokyo",KST:"Asia/Seoul",CST_CN:"Asia/Shanghai",HKT:"Asia/Hong_Kong",SGT:"Asia/Singapore",AEST:"Australia/Sydney",AEDT:"Australia/Sydney",ACST:"Australia/Adelaide",ACDT:"Australia/Adelaide",AWST:"Australia/Perth",NZST:"Pacific/Auckland",NZDT:"Pacific/Auckland","US/Eastern":"America/New_York","US/Central":"America/Chicago","US/Mountain":"America/Denver","US/Pacific":"America/Los_Angeles","US/Alaska":"America/Anchorage","US/Hawaii":"Pacific/Honolulu","Canada/Eastern":"America/Toronto","Canada/Central":"America/Regina","Canada/Mountain":"America/Denver","Canada/Pacific":"America/Vancouver","Canada/Atlantic":"America/Halifax","Canada/Newfoundland":"America/St_Johns","Mexico/General":"America/Mexico_City","Brazil/East":"America/Sao_Paulo","Chile/Continental":"America/Santiago",GB:"Europe/London","GB-Eire":"Europe/London",Eire:"Europe/Dublin",Israel:"Asia/Jerusalem",Japan:"Asia/Tokyo",Singapore:"Asia/Singapore",Hongkong:"Asia/Hong_Kong",ROK:"Asia/Seoul",PRC:"Asia/Shanghai","Australia/NSW":"Australia/Sydney","Australia/Victoria":"Australia/Melbourne","Australia/Queensland":"Australia/Brisbane","Australia/South":"Australia/Adelaide","Australia/Tasmania":"Australia/Hobart","Australia/West":"Australia/Perth","Australia/North":"Australia/Darwin",NZ:"Pacific/Auckland"}}getTimezone(e){return this.aliases[e]&&(e=this.aliases[e]),this.timezones[e]||null}getAllTimezones(){return Object.keys(this.timezones)}isValidTimezone(e){return this.aliases[e]!==void 0||this.timezones[e]!==void 0}resolveAlias(e){return this.aliases[e]||e}getTimezonesByOffset(e){return Object.entries(this.timezones).filter(([t,s])=>s.offset===e).map(([t,s])=>t)}getCommonTimezones(){return{Americas:["America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Mexico_City","America/Sao_Paulo"],Europe:["Europe/London","Europe/Paris","Europe/Berlin","Europe/Moscow","Europe/Rome","Europe/Madrid","Europe/Amsterdam"],Asia:["Asia/Tokyo","Asia/Shanghai","Asia/Hong_Kong","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Asia/Seoul"],"Australia/Pacific":["Australia/Sydney","Australia/Melbourne","Australia/Brisbane","Australia/Perth","Pacific/Auckland","Pacific/Honolulu"],Africa:["Africa/Cairo","Africa/Lagos","Africa/Johannesburg","Africa/Nairobi"]}}}class A{constructor(){this.database=new C,this.offsetCache=new Map,this.dstCache=new Map,this.maxCacheSize=1e3,this.cacheHits=0,this.cacheMisses=0}convertTimezone(e,t,s){if(!e)return null;if(t===s)return new Date(e);const i=this.getTimezoneOffset(e,t),n=(this.getTimezoneOffset(e,s)-i)*60*1e3;return new Date(e.getTime()+n)}toUTC(e,t){if(!e)return null;if(t==="UTC")return new Date(e);const s=this.getTimezoneOffset(e,t);return new Date(e.getTime()+s*60*1e3)}fromUTC(e,t){if(!e)return null;if(t==="UTC")return new Date(e);const s=this.getTimezoneOffset(e,t);return new Date(e.getTime()-s*60*1e3)}getTimezoneOffset(e,t){t=this.database.resolveAlias(t);const s=`${t}_${e.getFullYear()}_${e.getMonth()}_${e.getDate()}`;if(this.offsetCache.has(s))return this.cacheHits++,this._manageCacheSize(),this.offsetCache.get(s);if(this.cacheMisses++,typeof Intl<"u"&&Intl.DateTimeFormat)try{const r=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(e),c=(new Date(r.find(l=>l.type==="year").value,r.find(l=>l.type==="month").value-1,r.find(l=>l.type==="day").value,r.find(l=>l.type==="hour").value,r.find(l=>l.type==="minute").value,r.find(l=>l.type==="second").value).getTime()-e.getTime())/(1e3*60);return this.offsetCache.set(s,-c),this._manageCacheSize(),-c}catch{}const i=this.database.getTimezone(t);if(!i)throw new Error(`Unknown timezone: ${t}`);let a=i.offset;return i.dst&&this.isDST(e,t,i.dst)&&(a+=i.dst.offset),this.offsetCache.set(s,a),this._manageCacheSize(),a}isDST(e,t,s=null){if(!s){const r=this.database.getTimezone(t);if(!r||!r.dst)return!1;s=r.dst}const i=e.getFullYear(),a=this.getNthWeekdayOfMonth(i,s.start.month,s.start.week,s.start.day),n=this.getNthWeekdayOfMonth(i,s.end.month,s.end.week,s.end.day);return a>n?e>=a||e<n:e>=a&&e<n}getNthWeekdayOfMonth(e,t,s,i){const a=new Date(e,t,1),n=a.getDay();let r=i-n;if(r<0&&(r+=7),s>0)a.setDate(1+r+(s-1)*7);else{const o=new Date(e,t+1,0).getDate();a.setDate(o);let l=a.getDay()-i;l<0&&(l+=7),a.setDate(o-l+(s+1)*7)}return a}getCommonTimezones(){const e=new Date;return[{value:"America/New_York",label:"Eastern Time (New York)",region:"Americas"},{value:"America/Chicago",label:"Central Time (Chicago)",region:"Americas"},{value:"America/Denver",label:"Mountain Time (Denver)",region:"Americas"},{value:"America/Phoenix",label:"Mountain Time - Arizona (Phoenix)",region:"Americas"},{value:"America/Los_Angeles",label:"Pacific Time (Los Angeles)",region:"Americas"},{value:"America/Anchorage",label:"Alaska Time (Anchorage)",region:"Americas"},{value:"Pacific/Honolulu",label:"Hawaii Time (Honolulu)",region:"Pacific"},{value:"America/Toronto",label:"Eastern Time (Toronto)",region:"Americas"},{value:"America/Vancouver",label:"Pacific Time (Vancouver)",region:"Americas"},{value:"America/Mexico_City",label:"Central Time (Mexico City)",region:"Americas"},{value:"America/Sao_Paulo",label:"Brasilia Time (São Paulo)",region:"Americas"},{value:"Europe/London",label:"GMT/BST (London)",region:"Europe"},{value:"Europe/Paris",label:"Central European Time (Paris)",region:"Europe"},{value:"Europe/Berlin",label:"Central European Time (Berlin)",region:"Europe"},{value:"Europe/Moscow",label:"Moscow Time",region:"Europe"},{value:"Asia/Dubai",label:"Gulf Time (Dubai)",region:"Asia"},{value:"Asia/Kolkata",label:"India Time (Mumbai)",region:"Asia"},{value:"Asia/Shanghai",label:"China Time (Shanghai)",region:"Asia"},{value:"Asia/Tokyo",label:"Japan Time (Tokyo)",region:"Asia"},{value:"Asia/Seoul",label:"Korea Time (Seoul)",region:"Asia"},{value:"Asia/Singapore",label:"Singapore Time",region:"Asia"},{value:"Australia/Sydney",label:"Australian Eastern Time (Sydney)",region:"Oceania"},{value:"Australia/Melbourne",label:"Australian Eastern Time (Melbourne)",region:"Oceania"},{value:"Pacific/Auckland",label:"New Zealand Time (Auckland)",region:"Oceania"},{value:"UTC",label:"UTC",region:"UTC"}].map(s=>{const i=this.getTimezoneOffset(e,s.value),a=-i/60,n=Math.floor(Math.abs(a)),r=Math.round(Math.abs(a%1)*60),c=`UTC${a>=0?"+":"-"}${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`;return{...s,offset:c,offsetMinutes:-i}}).sort((s,i)=>s.offsetMinutes-i.offsetMinutes)}formatInTimezone(e,t,s={}){if(!e)return"";const a={...{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!0,timeZone:t},...s};try{return new Intl.DateTimeFormat("en-US",a).format(e)}catch{return this.fromUTC(this.toUTC(e,"UTC"),t).toLocaleString("en-US",s)}}getSystemTimezone(){if(typeof Intl<"u"&&Intl.DateTimeFormat)try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}const t=-new Date().getTimezoneOffset()/60;for(const[s,i]of Object.entries(this.database.timezones))if(i.offset/60===t)return s;return"UTC"}parseTimezone(e){if(!e)return"UTC";if(this.database.timezones.hasOwnProperty(e))return e;const t=e.toUpperCase();if(this.database.abbreviations&&this.database.abbreviations.hasOwnProperty(t))return this.database.abbreviations[t];const s=e.match(/^([+-])(\d{2}):?(\d{2})$/);if(s){const i=s[1]==="+"?1:-1,a=parseInt(s[2],10),n=parseInt(s[3],10),r=i*(a+n/60);for(const[o,c]of Object.entries(this.database.timezones))if(c.offset/60===r)return o}return"UTC"}getTimezoneDifference(e,t,s=new Date){const i=this.getTimezoneOffset(s,e);return(this.getTimezoneOffset(s,t)-i)/60}clearCache(){this.offsetCache.clear(),this.dstCache.clear(),this.cacheHits=0,this.cacheMisses=0}isValidTimezone(e){return this.database.isValidTimezone(e)}getCacheStats(){const e=this.cacheHits+this.cacheMisses>0?(this.cacheHits/(this.cacheHits+this.cacheMisses)*100).toFixed(2):0;return{offsetCacheSize:this.offsetCache.size,dstCacheSize:this.dstCache.size,maxCacheSize:this.maxCacheSize,cacheHits:this.cacheHits,cacheMisses:this.cacheMisses,hitRate:`${e}%`}}_manageCacheSize(){if(this.offsetCache.size>this.maxCacheSize){const e=Math.floor(this.offsetCache.size/2),t=Array.from(this.offsetCache.keys());for(let s=0;s<e;s++)this.offsetCache.delete(t[s])}if(this.dstCache.size>this.maxCacheSize/2){const e=Math.floor(this.dstCache.size/2),t=Array.from(this.dstCache.keys());for(let s=0;s<e;s++)this.dstCache.delete(t[s])}}}class E{static normalize(e){const t={...e};return t.start&&!(t.start instanceof Date)&&(t.start=new Date(t.start)),t.end&&!(t.end instanceof Date)&&(t.end=new Date(t.end)),t.end||(t.end=t.start?new Date(t.start):null),t.allDay&&t.start&&(t.start.setHours(0,0,0,0),t.end&&t.end.setHours(23,59,59,999)),t.id=String(t.id||"").trim(),t.title=String(t.title||"").trim(),t.description=String(t.description||"").trim(),t.location=String(t.location||"").trim(),t.attendees=Array.isArray(t.attendees)?t.attendees:[],t.reminders=Array.isArray(t.reminders)?t.reminders:[],e.category&&!e.categories?t.categories=[e.category]:t.categories?t.categories=Array.isArray(t.categories)?t.categories:[]:t.categories=[],t.attachments=Array.isArray(t.attachments)?t.attachments:[],["confirmed","tentative","cancelled"].includes(t.status)||(t.status="confirmed"),["public","private","confidential"].includes(t.visibility)||(t.visibility="public"),t.color&&!t.backgroundColor&&(t.backgroundColor=t.color),t.color&&!t.borderColor&&(t.borderColor=t.color),t}static validate(e){if(!e.id)throw new Error("Event must have an id");if(!e.title)throw new Error("Event must have a title");if(!e.start)throw new Error("Event must have a start date");if(!(e.start instanceof Date)||isNaN(e.start.getTime()))throw new Error("Invalid start date");if(e.end&&(!(e.end instanceof Date)||isNaN(e.end.getTime())))throw new Error("Invalid end date");if(e.end&&e.start&&e.end<e.start)throw new Error("Event end time cannot be before start time");if(e.recurring&&!e.recurrenceRule)throw new Error("Recurring events must have a recurrence rule");if(e.attendees&&e.attendees.length>0&&e.attendees.forEach((t,s)=>{if(!t.email||!t.name)throw new Error(`Attendee at index ${s} must have email and name`);if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.email))throw new Error(`Invalid email for attendee: ${t.email}`)}),e.reminders&&e.reminders.length>0&&e.reminders.forEach((t,s)=>{if(!t.method||t.minutesBefore==null)throw new Error(`Reminder at index ${s} must have method and minutesBefore`);if(t.minutesBefore<0)throw new Error("Reminder minutesBefore must be non-negative")}),e.timeZone)try{new Intl.DateTimeFormat("en-US",{timeZone:e.timeZone})}catch{throw new Error(`Invalid timezone: ${e.timeZone}`)}}constructor({id:e,title:t,start:s,end:i,allDay:a=!1,description:n="",location:r="",color:o=null,backgroundColor:c=null,borderColor:l=null,textColor:d=null,recurring:h=!1,recurrenceRule:b=null,timeZone:D=null,endTimeZone:k=null,status:S="confirmed",visibility:M="public",organizer:I=null,attendees:q=[],reminders:K=[],category:G,categories:Q,attachments:J=[],conferenceData:X=null,metadata:ee={},...te}){const u=E.normalize({id:e,title:t,start:s,end:i,allDay:a,description:n,location:r,color:o,backgroundColor:c,borderColor:l,textColor:d,recurring:h,recurrenceRule:b,timeZone:D,endTimeZone:k,status:S,visibility:M,organizer:I,attendees:q,reminders:K,category:G,categories:Q,attachments:J,conferenceData:X,metadata:ee,...te});E.validate(u),this.id=u.id,this.title=u.title,this._timezoneManager=new A,this.timeZone=u.timeZone||this._timezoneManager.getSystemTimezone(),this.endTimeZone=u.endTimeZone||this.timeZone,this.start=u.start,this.end=u.end,this.startUTC=this._timezoneManager.toUTC(this.start,this.timeZone),this.endUTC=this._timezoneManager.toUTC(this.end,this.endTimeZone),this.allDay=u.allDay,this.description=u.description,this.location=u.location,this.color=u.color,this.backgroundColor=u.backgroundColor,this.borderColor=u.borderColor,this.textColor=u.textColor,this.recurring=u.recurring,this.recurrenceRule=u.recurrenceRule,this._originalTimeZone=u.timeZone||null,this.status=u.status,this.visibility=u.visibility,this.organizer=u.organizer,this.attendees=[...u.attendees],this.reminders=[...u.reminders],this.categories=u.categories?[...u.categories]:[],this.attachments=[...u.attachments],this.conferenceData=u.conferenceData,this.metadata={...u.metadata},this._cache={},this._validateAttendees(),this._validateReminders()}get duration(){return this._cache.duration||(this._cache.duration=this.endUTC.getTime()-this.startUTC.getTime()),this._cache.duration}getStartInTimezone(e){return e===this.timeZone?new Date(this.start):this._timezoneManager.fromUTC(this.startUTC,e)}getEndInTimezone(e){return e===this.endTimeZone?new Date(this.end):this._timezoneManager.fromUTC(this.endUTC,e)}updateTimes(e,t,s){if(s||this.timeZone,this.start=e instanceof Date?e:new Date(e),this.end=t instanceof Date?t:new Date(t),s&&(this.timeZone=s,this.endTimeZone=s),this.startUTC=this._timezoneManager.toUTC(this.start,this.timeZone),this.endUTC=this._timezoneManager.toUTC(this.end,this.endTimeZone),this._cache={},this.endUTC<this.startUTC)throw new Error("Event end time cannot be before start time")}get durationMinutes(){return Math.floor(this.duration/(1e3*60))}get durationHours(){return this.duration/(1e3*60*60)}get isMultiDay(){if(!this._cache.hasOwnProperty("isMultiDay")){const e=this.start.toDateString(),t=this.end.toDateString();this._cache.isMultiDay=e!==t}return this._cache.isMultiDay}isRecurring(){return this.recurring&&this.recurrenceRule!==null}occursOn(e){e instanceof Date||(e=new Date(e));const t=e.toDateString(),s=this.start.toDateString(),i=this.end.toDateString();if(this.allDay)return e>=new Date(s)&&e<=new Date(i);if(this.isMultiDay){const a=new Date(t),n=new Date(t);return n.setHours(23,59,59,999),this.start<=n&&this.end>=a}else return s===t}overlaps(e){if(e instanceof E)return!(this.end<=e.start||this.start>=e.end);if(e&&e.start&&e.end)return!(this.end<=e.start||this.start>=e.end);throw new Error("Parameter must be an Event instance or have start/end properties")}contains(e){return e instanceof Date||(e=new Date(e)),e>=this.start&&e<=this.end}clone(e={}){return new E({id:this.id,title:this.title,start:new Date(this.start),end:new Date(this.end),allDay:this.allDay,description:this.description,location:this.location,color:this.color,backgroundColor:this.backgroundColor,borderColor:this.borderColor,textColor:this.textColor,recurring:this.recurring,recurrenceRule:this.recurrenceRule,timeZone:this.timeZone,status:this.status,visibility:this.visibility,organizer:this.organizer?{...this.organizer}:null,attendees:this.attendees.map(t=>({...t})),reminders:this.reminders.map(t=>({...t})),categories:[...this.categories],attachments:this.attachments.map(t=>({...t})),conferenceData:this.conferenceData?{...this.conferenceData}:null,metadata:{...this.metadata},...e})}toObject(){return{id:this.id,title:this.title,start:this.start.toISOString(),end:this.end.toISOString(),allDay:this.allDay,description:this.description,location:this.location,color:this.color,backgroundColor:this.backgroundColor,borderColor:this.borderColor,textColor:this.textColor,recurring:this.recurring,recurrenceRule:this.recurrenceRule,timeZone:this.timeZone,status:this.status,visibility:this.visibility,organizer:this.organizer,attendees:this.attendees,reminders:this.reminders,categories:this.categories,attachments:this.attachments,conferenceData:this.conferenceData,metadata:{...this.metadata}}}static fromObject(e){return new E(e)}equals(e){return e instanceof E?this.id===e.id&&this.title===e.title&&this.start.getTime()===e.start.getTime()&&this.end.getTime()===e.end.getTime()&&this.allDay===e.allDay&&this.description===e.description&&this.location===e.location&&this.recurring===e.recurring&&this.recurrenceRule===e.recurrenceRule&&this.status===e.status:!1}addAttendee(e){if(!e||!e.email)throw new Error("Attendee must have an email");return this.hasAttendee(e.email)?!1:(e.id||(e.id=`attendee_${Date.now()}_${Math.random().toString(36).substr(2,9)}`),e.responseStatus=e.responseStatus||"needs-action",e.role=e.role||"required",this.attendees.push(e),!0)}removeAttendee(e){const t=this.attendees.findIndex(s=>s.email===e||s.id===e);return t!==-1?(this.attendees.splice(t,1),!0):!1}updateAttendeeResponse(e,t){const s=this.getAttendee(e);return s?(s.responseStatus=t,s.responseTime=new Date,!0):!1}getAttendee(e){return this.attendees.find(t=>t.email===e)||null}hasAttendee(e){return this.attendees.some(t=>t.email===e)}getAttendeesByStatus(e){return this.attendees.filter(t=>t.responseStatus===e)}getAttendeeCounts(){return this.attendees.reduce((e,t)=>{const s=t.responseStatus||"needs-action";return e[s]=(e[s]||0)+1,e},{})}addReminder(e){if(!e||typeof e.minutesBefore!="number")throw new Error("Reminder must have minutesBefore property");return e.id||(e.id=`reminder_${Date.now()}_${Math.random().toString(36).substr(2,9)}`),e.method=e.method||"popup",e.enabled=e.enabled!==!1,this.reminders.some(s=>s.method===e.method&&s.minutesBefore===e.minutesBefore)?!1:(this.reminders.push(e),!0)}removeReminder(e){const t=this.reminders.findIndex(s=>s.id===e);return t!==-1?(this.reminders.splice(t,1),!0):!1}getActiveReminders(){return this.reminders.filter(e=>e.enabled!==!1)}getReminderTriggerTimes(){return this.getActiveReminders().map(e=>{const t=new Date(this.start);return t.setMinutes(t.getMinutes()-e.minutesBefore),t})}addCategory(e){if(!e||typeof e!="string")throw new Error("Category must be a non-empty string");const t=e.trim().toLowerCase();return this.hasCategory(t)?!1:(this.categories.push(t),!0)}removeCategory(e){const t=e.trim().toLowerCase(),s=this.categories.findIndex(i=>i.toLowerCase()===t);return s!==-1?(this.categories.splice(s,1),!0):!1}get category(){return this.categories&&this.categories.length>0?this.categories[0]:null}hasCategory(e){const t=e.trim().toLowerCase();return this.categories.some(s=>s.toLowerCase()===t)}hasAnyCategory(e){return e.some(t=>this.hasCategory(t))}hasAllCategories(e){return e.every(t=>this.hasCategory(t))}_validateAttendees(){for(const e of this.attendees){if(!e.email)throw new Error("All attendees must have an email address");if(e.name||(e.name=e.email),!this._isValidEmail(e.email))throw new Error(`Invalid attendee email: ${e.email}`)}}_validateReminders(){for(const e of this.reminders){if(typeof e.minutesBefore!="number"||e.minutesBefore<0)throw new Error("Reminder minutesBefore must be a positive number");if(!["email","popup","sms"].includes(e.method))throw new Error(`Invalid reminder method: ${e.method}`)}}_isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}get isCancelled(){return this.status==="cancelled"}get isTentative(){return this.status==="tentative"}get isConfirmed(){return this.status==="confirmed"}get isPrivate(){return this.visibility==="private"}get isPublic(){return this.visibility==="public"}get hasAttendees(){return this.attendees.length>0}get hasReminders(){return this.reminders.length>0}get isMeeting(){return this.hasAttendees||this.conferenceData!==null}get isVirtual(){return this.conferenceData!==null}}let f=class x{static startOfDay(e){const t=new Date(e);return t.setHours(0,0,0,0),t}static endOfDay(e){const t=new Date(e);return t.setHours(23,59,59,999),t}static startOfWeek(e,t=0){const s=new Date(e),i=s.getDay(),a=(i<t?7:0)+i-t;return s.setTime(s.getTime()-a*24*60*60*1e3),s.setHours(0,0,0,0),s}static endOfWeek(e,t=0){const s=x.startOfWeek(e,t);return s.setTime(s.getTime()+6*24*60*60*1e3),s.setHours(23,59,59,999),s}static startOfMonth(e){return new Date(e.getFullYear(),e.getMonth(),1,0,0,0,0)}static endOfMonth(e){return new Date(e.getFullYear(),e.getMonth()+1,0,23,59,59,999)}static startOfYear(e){return new Date(e.getFullYear(),0,1,0,0,0,0)}static endOfYear(e){return new Date(e.getFullYear(),11,31,23,59,59,999)}static addDays(e,t){const s=new Date(e);return s.setTime(s.getTime()+t*24*60*60*1e3),s}static addWeeks(e,t){return x.addDays(e,t*7)}static addMonths(e,t){const s=new Date(e),i=s.getDate();return s.setMonth(s.getMonth()+t),s.getDate()!==i&&s.setDate(0),s}static addYears(e,t){const s=new Date(e);return s.setFullYear(s.getFullYear()+t),s}static getUTCDateString(e){const t=e.getUTCFullYear(),s=String(e.getUTCMonth()+1).padStart(2,"0"),i=String(e.getUTCDate()).padStart(2,"0");return`${t}-${s}-${i}`}static getLocalDateString(e){const t=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`${t}-${s}-${i}`}static isToday(e){const t=new Date;return e.toDateString()===t.toDateString()}static isPast(e){return e<new Date}static isFuture(e){return e>new Date}static isSameDay(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}static isSameWeek(e,t,s=0){const i=x.startOfWeek(e,s),a=x.startOfWeek(t,s);return i.toDateString()===a.toDateString()}static isSameMonth(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()}static isSameYear(e,t){return e.getFullYear()===t.getFullYear()}static differenceInDays(e,t){const s=e.getTime()-t.getTime();return Math.floor(s/(1e3*60*60*24))}static differenceInWeeks(e,t){return Math.floor(x.differenceInDays(e,t)/7)}static differenceInMonths(e,t){const s=e.getFullYear()-t.getFullYear(),i=e.getMonth()-t.getMonth();return s*12+i}static getWeekNumber(e){const t=new Date(e.getFullYear(),0,1),s=(e-t)/864e5;return Math.ceil((s+t.getDay()+1)/7)}static getDayOfWeek(e,t=0){return(e.getDay()-t+7)%7}static getDaysInMonth(e){return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()}static format(e,t="en-US",s={}){return new Intl.DateTimeFormat(t,s).format(e)}static getMonthName(e,t="en-US",s="long"){return x.format(e,t,{month:s})}static getDayName(e,t="en-US",s="long"){return x.format(e,t,{weekday:s})}static formatTime(e,t="en-US",s=!1){return x.format(e,t,{hour:"numeric",minute:"2-digit",hour12:!s})}static parseTime(e){const[t,s]=e.split(":").map(Number);return{hours:t,minutes:s}}static setTime(e,t){const s=new Date(e),{hours:i,minutes:a}=x.parseTime(t);return s.setHours(i,a,0,0),s}static isLeapYear(e){return e%4===0&&e%100!==0||e%400===0}static getDateRange(e,t){const s=[],i=new Date(e),a=t.getTime();for(;i.getTime()<=a;)s.push(new Date(i)),i.setTime(i.getTime()+24*60*60*1e3);return s}static clone(e){return new Date(e)}static isValidDate(e){return e instanceof Date&&!isNaN(e.getTime())}static toTimeZone(e,t){const i=new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(e),a={};return i.forEach(n=>{n.type!=="literal"&&(a[n.type]=n.value)}),new Date(`${a.year}-${a.month}-${a.day}T${a.hour}:${a.minute}:${a.second}`)}static getTimezoneOffset(e,t){const s=new Date(e.toLocaleString("en-US",{timeZone:"UTC"})),i=new Date(e.toLocaleString("en-US",{timeZone:t}));return(s.getTime()-i.getTime())/6e4}static isDST(e,t){const s=new Date(e.getFullYear(),0,1),i=new Date(e.getFullYear(),6,1),a=x.getTimezoneOffset(s,t),n=x.getTimezoneOffset(i,t),r=x.getTimezoneOffset(e,t);return Math.max(a,n)===r}static addHoursWithDST(e,t,s){const i=new Date(e),a=x.getTimezoneOffset(e,s);i.setTime(i.getTime()+t*60*60*1e3);const n=x.getTimezoneOffset(i,s);if(a!==n){const r=(n-a)*6e4;i.setTime(i.getTime()+r)}return i}static createInTimeZone(e,t,s,i=0,a=0,n=0,r){const o=`${e}-${String(t+1).padStart(2,"0")}-${String(s).padStart(2,"0")}`,c=`${String(i).padStart(2,"0")}:${String(a).padStart(2,"0")}:${String(n).padStart(2,"0")}`,l=new Date(`${o}T${c}`),d=x.getTimezoneOffset(l,r),h=l.getTime()+d*6e4;return new Date(h)}};class H{static parse(e){if(typeof e=="object")return this.validateRule(e);const t={freq:null,interval:1,count:null,until:null,byDay:[],byWeekNo:[],byMonth:[],byMonthDay:[],byYearDay:[],bySetPos:[],byHour:[],byMinute:[],bySecond:[],wkst:"MO",exceptions:[],tzid:null},s=e.toUpperCase().split(";");for(const i of s){const[a,n]=i.split("=");switch(a){case"FREQ":t.freq=this.parseFrequency(n);break;case"INTERVAL":t.interval=parseInt(n,10),t.interval<1&&(t.interval=1);break;case"COUNT":t.count=parseInt(n,10);break;case"UNTIL":t.until=this.parseDateTime(n);break;case"BYDAY":t.byDay=this.parseByDay(n);break;case"BYWEEKNO":t.byWeekNo=this.parseIntList(n);break;case"BYMONTH":t.byMonth=this.parseIntList(n);break;case"BYMONTHDAY":t.byMonthDay=this.parseIntList(n);break;case"BYYEARDAY":t.byYearDay=this.parseIntList(n);break;case"BYSETPOS":t.bySetPos=this.parseIntList(n);break;case"BYHOUR":t.byHour=this.parseIntList(n);break;case"BYMINUTE":t.byMinute=this.parseIntList(n);break;case"BYSECOND":t.bySecond=this.parseIntList(n);break;case"WKST":t.wkst=n;break;case"EXDATE":t.exceptions=this.parseExceptionDates(n);break;case"TZID":t.tzid=n;break}}return this.validateRule(t)}static parseFrequency(e){return["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"].includes(e)?e:"DAILY"}static parseByDay(e){const t=e.split(","),s=["SU","MO","TU","WE","TH","FR","SA"],i=[];for(const a of t){const r=a.trim().toUpperCase().match(/^([+-]?\d*)([A-Z]{2})$/);if(r){const[o,c,l]=r;s.includes(l)&&i.push(c?`${c}${l}`:l)}}return i}static parseIntList(e){return e.split(",").map(t=>parseInt(t.trim(),10)).filter(t=>!isNaN(t))}static parseDateTime(e){if(e.length===8){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10);return new Date(t,s,i)}if(e.length===15&&e[8]==="T"){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(9,2),10),n=parseInt(e.substr(11,2),10),r=parseInt(e.substr(13,2),10);return new Date(t,s,i,a,n,r)}if(e.length===16&&e[8]==="T"&&e[15]==="Z"){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(9,2),10),n=parseInt(e.substr(11,2),10),r=parseInt(e.substr(13,2),10);return new Date(Date.UTC(t,s,i,a,n,r))}return new Date(e)}static parseExceptionDates(e){return e.split(",").map(s=>this.parseDateTime(s.trim()))}static validateRule(e){if(e.freq||(e.freq="DAILY"),e.count&&e.until)throw new Error("RRULE cannot have both COUNT and UNTIL");e.interval<1&&(e.interval=1);const t=(s,i,a)=>s.filter(n=>n>=i&&n<=a);return e.byMonth=t(e.byMonth||[],1,12),e.byMonthDay=t(e.byMonthDay||[],-31,31).filter(s=>s!==0),e.byYearDay=t(e.byYearDay||[],-366,366).filter(s=>s!==0),e.byWeekNo=t(e.byWeekNo||[],-53,53).filter(s=>s!==0),e.byHour=t(e.byHour||[],0,23),e.byMinute=t(e.byMinute||[],0,59),e.bySecond=t(e.bySecond||[],0,59),e}static buildRRule(e){const t=[];if(t.push(`FREQ=${e.freq}`),e.interval&&e.interval>1&&t.push(`INTERVAL=${e.interval}`),e.count?t.push(`COUNT=${e.count}`):e.until&&t.push(`UNTIL=${this.formatDateTime(e.until)}`),e.byDay&&e.byDay.length>0){const s=e.byDay.map(i=>i.nth?`${i.nth}${i.weekday}`:i.weekday).join(",");t.push(`BYDAY=${s}`)}return e.byMonth&&e.byMonth.length>0&&t.push(`BYMONTH=${e.byMonth.join(",")}`),e.byMonthDay&&e.byMonthDay.length>0&&t.push(`BYMONTHDAY=${e.byMonthDay.join(",")}`),e.byYearDay&&e.byYearDay.length>0&&t.push(`BYYEARDAY=${e.byYearDay.join(",")}`),e.byWeekNo&&e.byWeekNo.length>0&&t.push(`BYWEEKNO=${e.byWeekNo.join(",")}`),e.bySetPos&&e.bySetPos.length>0&&t.push(`BYSETPOS=${e.bySetPos.join(",")}`),e.byHour&&e.byHour.length>0&&t.push(`BYHOUR=${e.byHour.join(",")}`),e.byMinute&&e.byMinute.length>0&&t.push(`BYMINUTE=${e.byMinute.join(",")}`),e.bySecond&&e.bySecond.length>0&&t.push(`BYSECOND=${e.bySecond.join(",")}`),e.wkst&&e.wkst!=="MO"&&t.push(`WKST=${e.wkst}`),t.join(";")}static formatDateTime(e){const t=e.getUTCFullYear(),s=String(e.getUTCMonth()+1).padStart(2,"0"),i=String(e.getUTCDate()).padStart(2,"0"),a=String(e.getUTCHours()).padStart(2,"0"),n=String(e.getUTCMinutes()).padStart(2,"0"),r=String(e.getUTCSeconds()).padStart(2,"0");return`${t}${s}${i}T${a}${n}${r}Z`}static getDescription(e){const t={SECONDLY:"second",MINUTELY:"minute",HOURLY:"hour",DAILY:"day",WEEKLY:"week",MONTHLY:"month",YEARLY:"year"},s={SU:"Sunday",MO:"Monday",TU:"Tuesday",WE:"Wednesday",TH:"Thursday",FR:"Friday",SA:"Saturday"},i={1:"first",2:"second",3:"third",4:"fourth",5:"fifth","-1":"last","-2":"second to last"};let a="Every";if(e.interval>1&&(a+=` ${e.interval}`),a+=` ${t[e.freq]}`,e.interval>1&&(a+="s"),e.byDay&&e.byDay.length>0){if(e.freq==="WEEKLY"){const n=e.byDay.map(r=>s[r.weekday]).join(", ");a+=` on ${n}`}else if(e.freq==="MONTHLY"||e.freq==="YEARLY"){const n=e.byDay.map(r=>r.nth?`the ${i[r.nth]||r.nth} ${s[r.weekday]}`:s[r.weekday]).join(", ");a+=` on ${n}`}}if(e.byMonthDay&&e.byMonthDay.length>0){const n=e.byMonthDay.map(r=>r<0?`${Math.abs(r)} day(s) from the end`:`day ${r}`).join(", ");a+=` on ${n}`}if(e.byMonth&&e.byMonth.length>0){const n=["January","February","March","April","May","June","July","August","September","October","November","December"],r=e.byMonth.map(o=>n[o-1]).join(", ");a+=` in ${r}`}return e.count?a+=`, ${e.count} time${e.count>1?"s":""}`:e.until&&(a+=`, until ${e.until.toLocaleDateString()}`),a}}class U{static expandEvent(e,t,s,i=365,a=null){if(!e.recurring||!e.recurrenceRule)return[{start:e.start,end:e.end,timezone:e.timeZone}];const n=this.parseRule(e.recurrenceRule),r=[],o=e.end-e.start,c=a||e.timeZone||"UTC",l=new A;let d=new Date(e.start),h=0;n.until&&n.until<s&&(s=n.until);let b=l.getTimezoneOffset(d,c);for(;d<=s&&h<i;){if(d>=t){const D=new Date(d),k=new Date(d.getTime()+o),S=l.getTimezoneOffset(D,c);if(S!==b){const M=b-S;D.setMinutes(D.getMinutes()+M),k.setMinutes(k.getMinutes()+M)}b=S,this.isException(D,n,e.id)||r.push({start:D,end:k,recurringEventId:e.id,timezone:c,originalStart:e.start})}if(d=this.getNextOccurrence(d,n,c),h++,n.count&&h>=n.count)break}return r}static parseRule(e){return H.parse(e)}static getNextOccurrence(e,t,s="UTC"){const i=new Date(e);switch(t.freq){case"DAILY":i.setDate(i.getDate()+t.interval);break;case"WEEKLY":if(t.byDay&&t.byDay.length>0){let n=0;for(i.setDate(i.getDate()+1);!this.matchesByDay(i,t.byDay)&&n<8;)i.setDate(i.getDate()+1),n++;n>=8&&(console.warn("RecurrenceEngine: Invalid byDay rule, falling back to weekly interval"),i.setDate(i.getDate()+7*t.interval-8))}else i.setDate(i.getDate()+7*t.interval);break;case"MONTHLY":if(t.byMonthDay&&t.byMonthDay.length>0){const a=i.getMonth();i.setMonth(a+t.interval),i.setDate(t.byMonthDay[0])}else t.byDay&&t.byDay.length>0?(i.setMonth(i.getMonth()+t.interval),this.setToWeekdayOfMonth(i,t.byDay[0],t.bySetPos[0]||1)):i.setMonth(i.getMonth()+t.interval);break;case"YEARLY":t.byMonth&&t.byMonth.length>0?(i.setFullYear(i.getFullYear()+t.interval),i.setMonth(t.byMonth[0]-1)):i.setFullYear(i.getFullYear()+t.interval);break;default:i.setTime(i.getTime()+24*60*60*1e3)}return i}static matchesByDay(e,t){const s={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},i=e.getDay();return t.some(a=>{const n=a.match(/^(-?\d+)?([A-Z]{2})$/);if(n){const r=n[2];return s[r]===i}return!1})}static setToWeekdayOfMonth(e,t,s=1){const i={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},a=t.match(/^(-?\d+)?([A-Z]{2})$/),n=a?a[2]:t,r=i[n];for(e.setDate(1);e.getDay()!==r;)e.setDate(e.getDate()+1);if(s>1)e.setDate(e.getDate()+7*(s-1));else if(s===-1){const o=new Date(e);for(o.setMonth(o.getMonth()+1),o.setDate(0);o.getDay()!==r;)o.setDate(o.getDate()-1);e.setTime(o.getTime())}}static isException(e,t,s=null){if(!t.exceptions||t.exceptions.length===0)return!1;const i=e.toDateString(),a=e.getTime();return t.exceptions.some(n=>{if(typeof n=="object"&&n.date){const r=n.date instanceof Date?n.date:new Date(n.date);return n.matchTime?Math.abs(r.getTime()-a)<1e3:r.toDateString()===i}else return(n instanceof Date?n:new Date(n)).toDateString()===i})}static addExceptions(e,t,s={}){return e.exceptions||(e.exceptions=[]),(Array.isArray(t)?t:[t]).forEach(a=>{s.reason||s.matchTime?e.exceptions.push({date:a,reason:s.reason,matchTime:s.matchTime||!1}):e.exceptions.push(a)}),e}static parseDate(e){if(e.length===8){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10);return new Date(t,s,i)}else if(e.length===15||e.length===16){const t=parseInt(e.substr(0,4),10),s=parseInt(e.substr(4,2),10)-1,i=parseInt(e.substr(6,2),10),a=parseInt(e.substr(9,2),10),n=parseInt(e.substr(11,2),10),r=parseInt(e.substr(13,2),10);return e.endsWith("Z")?new Date(Date.UTC(t,s,i,a,n,r)):new Date(t,s,i,a,n,r)}return new Date(e)}static getDescription(e){typeof e=="string"&&(e=this.parseRule(e));let t="";const s=e.interval||1;switch(e.freq){case"DAILY":t=s===1?"Daily":`Every ${s} days`;break;case"WEEKLY":if(t=s===1?"Weekly":`Every ${s} weeks`,e.byDay&&e.byDay.length>0){const i=e.byDay.map(a=>this.getDayName(a)).join(", ");t+=` on ${i}`}break;case"MONTHLY":t=s===1?"Monthly":`Every ${s} months`,e.byMonthDay&&e.byMonthDay.length>0&&(t+=` on day ${e.byMonthDay.join(", ")}`);break;case"YEARLY":t=s===1?"Yearly":`Every ${s} years`;break}return e.count?t+=`, ${e.count} times`:e.until&&(t+=`, until ${e.until.toLocaleDateString()}`),t}static getDayName(e){const t={SU:"Sunday",MO:"Monday",TU:"Tuesday",WE:"Wednesday",TH:"Thursday",FR:"Friday",SA:"Saturday"},s=e.match(/^(-?\d+)?([A-Z]{2})$/),i=s?s[2]:e,a=s&&s[1]?parseInt(s[1],10):null;let n=t[i]||e;return a&&(n=`${a===-1?"Last":["","1st","2nd","3rd","4th","5th"][a]||`${a}th`} ${n}`),n}}class z{constructor(e=100){this.capacity=e,this.cache=new Map,this.hits=0,this.misses=0,this.evictions=0}get(e){if(!this.cache.has(e)){this.misses++;return}const t=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,t),this.hits++,t}put(e,t){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){const s=this.cache.keys().next().value;this.cache.delete(s),this.evictions++}this.cache.set(e,t)}has(e){return this.cache.has(e)}delete(e){return this.cache.delete(e)}clear(){this.cache.clear(),this.hits=0,this.misses=0,this.evictions=0}getStats(){const e=this.hits+this.misses>0?(this.hits/(this.hits+this.misses)*100).toFixed(2):0;return{size:this.cache.size,capacity:this.capacity,hits:this.hits,misses:this.misses,evictions:this.evictions,hitRate:`${e}%`}}keys(){return Array.from(this.cache.keys())}get size(){return this.cache.size}}class P{constructor(e={}){this.config={checkInterval:3e4,memoryThreshold:.8,criticalThreshold:.95,minCacheSize:10,maxCacheSize:1e4,adaptiveScaling:!0,...e},this.caches=new Map,this.stats={adjustments:0,emergencyClears:0,lastMemoryUsage:0,lastCheckTime:null,cacheResizes:[]},this.monitoringInterval=null,this.config.adaptiveScaling&&this.startMonitoring()}registerCache(e,t,s={}){this.caches.set(e,{cache:t,priority:s.priority||1,currentCapacity:s.initialCapacity||100,minCapacity:s.minCapacity||this.config.minCacheSize,maxCapacity:s.maxCapacity||this.config.maxCacheSize,scaleFactor:s.scaleFactor||.5,lastAccess:Date.now()})}unregisterCache(e){this.caches.delete(e)}startMonitoring(){this.monitoringInterval||(this.monitoringInterval=setInterval(()=>{this.checkMemoryPressure()},this.config.checkInterval),this.checkMemoryPressure())}stopMonitoring(){this.monitoringInterval&&(clearInterval(this.monitoringInterval),this.monitoringInterval=null)}async checkMemoryPressure(){const e=await this.getMemoryUsage();this.stats.lastMemoryUsage=e,this.stats.lastCheckTime=new Date,e>this.config.criticalThreshold?this.emergencyClear():e>this.config.memoryThreshold?this.reduceCacheSizes(e):e<this.config.memoryThreshold-.2&&this.increaseCacheSizes()}async getMemoryUsage(){if(typeof performance<"u"&&performance.memory){const e=performance.memory;if(e.jsHeapSizeLimit&&e.usedJSHeapSize)return e.usedJSHeapSize/e.jsHeapSizeLimit}try{const t=(typeof globalThis<"u"?globalThis:{}).process;if(t&&typeof t=="object"){const s=t.memoryUsage;if(typeof s=="function"){const i=s.call(t);return i.heapUsed/i.heapTotal}}}catch{}return this.estimateMemoryUsage()}estimateMemoryUsage(){let e=0,t=0;for(const[s,i]of this.caches)i.cache.size!==void 0&&(e+=i.cache.size,t+=i.maxCapacity);return t>0?e/t:.5}reduceCacheSizes(e){const t=(e-this.config.memoryThreshold)/(this.config.criticalThreshold-this.config.memoryThreshold),s=Array.from(this.caches.entries()).sort((i,a)=>i[1].priority-a[1].priority);for(const[i,a]of s){const n=Math.floor(a.currentCapacity*a.scaleFactor*t),r=Math.max(a.minCapacity,a.currentCapacity-n);r<a.currentCapacity&&this.resizeCache(i,a,r)}this.stats.adjustments++}increaseCacheSizes(){for(const[e,t]of this.caches)if(Date.now()-t.lastAccess<6e4){const i=Math.floor(t.currentCapacity*.2),a=Math.min(t.maxCapacity,t.currentCapacity+i);a>t.currentCapacity&&this.resizeCache(e,t,a)}}resizeCache(e,t,s){const i=t.currentCapacity;t.currentCapacity=s,t.cache.capacity!==void 0&&(t.cache.capacity=s),t.cache.size>s&&this.evictExcessItems(t.cache,s),this.stats.cacheResizes.push({cache:e,timestamp:new Date,oldCapacity:i,newCapacity:s,reason:s<i?"pressure":"available"}),this.stats.cacheResizes.length>100&&this.stats.cacheResizes.shift()}evictExcessItems(e,t){if(e.size<=t)return;const s=e.size-t;if(e.keys){const i=Array.from(e.keys());for(let a=0;a<s;a++)e.delete(i[a])}else e.clear&&e.clear()}emergencyClear(){for(const[e,t]of this.caches)t.cache.clear&&t.cache.clear(),t.currentCapacity=t.minCapacity;this.stats.emergencyClears++,console.warn("AdaptiveMemoryManager: Emergency cache clear triggered")}touchCache(e){const t=this.caches.get(e);t&&(t.lastAccess=Date.now())}getStats(){const e={};for(const[t,s]of this.caches)e[t]={size:s.cache.size||0,capacity:s.currentCapacity,priority:s.priority,lastAccess:new Date(s.lastAccess)};return{...this.stats,memoryUsagePercent:`${(this.stats.lastMemoryUsage*100).toFixed(2)}%`,totalCaches:this.caches.size,cacheStats:e,monitoring:this.monitoringInterval!==null}}async checkNow(){await this.checkMemoryPressure()}setThresholds(e){e.memoryThreshold!==void 0&&(this.config.memoryThreshold=Math.max(.5,Math.min(.95,e.memoryThreshold))),e.criticalThreshold!==void 0&&(this.config.criticalThreshold=Math.max(this.config.memoryThreshold+.05,Math.min(1,e.criticalThreshold)))}destroy(){this.stopMonitoring(),this.caches.clear()}}class Y{constructor(e={}){this.config={enableCache:!0,cacheCapacity:500,maxIndexDays:365,batchSize:100,enableMetrics:!0,cleanupInterval:36e5,maxIndexAge:30*24*60*60*1e3,enableAdaptiveMemory:!0,...e},this.eventCache=new z(this.config.cacheCapacity),this.queryCache=new z(Math.floor(this.config.cacheCapacity/2)),this.dateRangeCache=new z(Math.floor(this.config.cacheCapacity/4)),this.config.enableAdaptiveMemory&&(this.memoryManager=new P({checkInterval:3e4,memoryThreshold:.75,criticalThreshold:.9}),this.memoryManager.registerCache("events",this.eventCache,{priority:3,initialCapacity:this.config.cacheCapacity,minCapacity:50,maxCapacity:2e3}),this.memoryManager.registerCache("queries",this.queryCache,{priority:2,initialCapacity:Math.floor(this.config.cacheCapacity/2),minCapacity:25,maxCapacity:1e3}),this.memoryManager.registerCache("dateRanges",this.dateRangeCache,{priority:1,initialCapacity:Math.floor(this.config.cacheCapacity/4),minCapacity:10,maxCapacity:500})),this.lazyIndexes=new Map,this.pendingIndexes=new Map,this.batchQueue=[],this.batchTimer=null,this.batchCallbacks=[],this.metrics={operations:{},averageTimes:{},slowQueries:[]},this.cleanupTimer=null,this.config.cleanupInterval>0&&this.startCleanupTimer()}measure(e,t){if(!this.config.enableMetrics)return t();const s=performance.now();try{const i=t(),a=performance.now()-s;return this.recordMetric(e,a),i}catch(i){const a=performance.now()-s;throw this.recordMetric(e,a,!0),i}}async measureAsync(e,t){if(!this.config.enableMetrics)return await t();const s=performance.now();try{const i=await t(),a=performance.now()-s;return this.recordMetric(e,a),i}catch(i){const a=performance.now()-s;throw this.recordMetric(e,a,!0),i}}recordMetric(e,t,s=!1){this.metrics.operations[e]||(this.metrics.operations[e]={count:0,totalTime:0,errors:0,min:1/0,max:0});const i=this.metrics.operations[e];i.count++,i.totalTime+=t,i.min=Math.min(i.min,t),i.max=Math.max(i.max,t),s&&i.errors++,this.metrics.averageTimes[e]=i.totalTime/i.count,t>100&&(this.metrics.slowQueries.push({operation:e,duration:t,timestamp:new Date,isError:s}),this.metrics.slowQueries.length>100&&this.metrics.slowQueries.shift())}getMetrics(){const e={cacheStats:{event:this.eventCache.getStats(),query:this.queryCache.getStats(),dateRange:this.dateRangeCache.getStats()},operations:{},slowestOperations:[],recentSlowQueries:this.metrics.slowQueries.slice(-10),memoryManagement:this.memoryManager?this.memoryManager.getStats():null};for(const[t,s]of Object.entries(this.metrics.operations))e.operations[t]={count:s.count,avgTime:`${(s.totalTime/s.count).toFixed(2)}ms`,minTime:`${s.min.toFixed(2)}ms`,maxTime:`${s.max.toFixed(2)}ms`,totalTime:`${s.totalTime.toFixed(2)}ms`,errors:s.errors,errorRate:`${(s.errors/s.count*100).toFixed(2)}%`};return e.slowestOperations=Object.entries(this.metrics.averageTimes).sort((t,s)=>s[1]-t[1]).slice(0,5).map(([t,s])=>({operation:t,avgTime:`${s.toFixed(2)}ms`})),e}shouldUseLazyIndexing(e){return Math.ceil((e.end-e.start)/864e5)>this.config.maxIndexDays}createLazyIndexMarkers(e){const t={eventId:e.id,start:e.start,end:e.end,indexed:new Set,pending:!1},s=new Date(e.start.getFullYear(),e.start.getMonth(),1),i=new Date(e.end.getFullYear(),e.end.getMonth(),1);return t.indexed.add(this.getMonthKey(s)),this.getMonthKey(s)!==this.getMonthKey(i)&&t.indexed.add(this.getMonthKey(i)),this.lazyIndexes.set(e.id,t),t}async expandLazyIndex(e,t,s){const i=this.lazyIndexes.get(e);if(!i)return new Set;if(i.pending)return this.pendingIndexes.get(e);i.pending=!0;const a=new Promise(n=>{setTimeout(()=>{const r=new Set,o=new Date(t);for(;o<=s;){const c=o.toDateString();i.indexed.has(c)||(r.add(c),i.indexed.add(c)),o.setDate(o.getDate()+1)}i.pending=!1,this.pendingIndexes.delete(e),n(r)},0)});return this.pendingIndexes.set(e,a),a}getMonthKey(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`}cache(e,t,s="event"){if(!this.config.enableCache)return;let i,a;switch(s){case"event":i=this.eventCache,a="events";break;case"query":i=this.queryCache,a="queries";break;case"dateRange":i=this.dateRangeCache,a="dateRanges";break;default:return}i.put(e,t),this.memoryManager&&this.memoryManager.touchCache(a)}getFromCache(e,t="event"){if(!this.config.enableCache)return;let s,i;switch(t){case"event":s=this.eventCache.get(e),i="events";break;case"query":s=this.queryCache.get(e),i="queries";break;case"dateRange":s=this.dateRangeCache.get(e),i="dateRanges";break;default:return}return s!==void 0&&this.memoryManager&&this.memoryManager.touchCache(i),s}invalidateEventCaches(e){this.eventCache.delete(e),this.queryCache.clear(),this.dateRangeCache.clear()}batch(e){return new Promise((t,s)=>{this.batchQueue.push(e),this.batchCallbacks.push({resolve:t,reject:s}),this.batchQueue.length>=this.config.batchSize?this.processBatch():this.batchTimer||(this.batchTimer=setTimeout(()=>this.processBatch(),10))})}processBatch(){if(this.batchTimer&&(clearTimeout(this.batchTimer),this.batchTimer=null),this.batchQueue.length===0)return;const e=this.batchQueue.splice(0),t=this.batchCallbacks.splice(0),s=[],i=[];e.forEach((a,n)=>{try{s[n]=a()}catch(r){i[n]=r}}),t.forEach((a,n)=>{i[n]?a.reject(i[n]):a.resolve(s[n])})}startCleanupTimer(){this.cleanupTimer=setInterval(()=>{this.cleanupOldIndexes()},this.config.cleanupInterval)}cleanupOldIndexes(){const e=Date.now(),t=this.config.maxIndexAge;for(const[s,i]of this.lazyIndexes)i.end.getTime()<e-t&&this.lazyIndexes.delete(s);this.metrics.slowQueries.length>100&&(this.metrics.slowQueries=this.metrics.slowQueries.slice(-100))}optimizeQuery(e,t){const s=this.getFromCache(e,"query");if(s!==void 0)return s;const i=this.measure(`query:${e}`,t);return this.cache(e,i,"query"),i}destroy(){this.cleanupTimer&&(clearInterval(this.cleanupTimer),this.cleanupTimer=null),this.batchTimer&&(clearTimeout(this.batchTimer),this.batchTimer=null),this.eventCache.clear(),this.queryCache.clear(),this.dateRangeCache.clear(),this.lazyIndexes.clear(),this.pendingIndexes.clear()}}class N{constructor(e){this.eventStore=e,this.conflictIdCounter=0}checkConflicts(e,t={}){const s={checkAttendees:!0,checkResources:!0,checkLocation:!0,ignoreAllDay:!1,excludeEventIds:[],includeStatuses:["confirmed","tentative"],bufferMinutes:0,...t};if(!e.start||!e.end)throw new Error("Event must have start and end dates");const i=[],a=new Set,n=new Set,r=new Date(e.start.getTime()-s.bufferMinutes*6e4),o=new Date(e.end.getTime()+s.bufferMinutes*6e4),c=this.eventStore.getEventsInRange(r,o,!1).filter(l=>!(l.id===e.id||s.excludeEventIds.includes(l.id)||!s.includeStatuses.includes(l.status)||s.ignoreAllDay&&(l.allDay||e.allDay)||l.status==="cancelled"));for(const l of c){const d=this._detectEventConflicts(e,l,s);d.length>0&&(i.push(...d),a.add(e.id),a.add(l.id),e.attendees&&e.attendees.forEach(h=>n.add(h.email)),l.attendees&&l.attendees.forEach(h=>n.add(h.email)))}return this._buildConflictSummary(i,a,n)}checkEventPairConflicts(e,t,s={}){const i={checkAttendees:!0,checkResources:!0,checkLocation:!0,bufferMinutes:0,...s};return this._detectEventConflicts(e,t,i)}getBusyPeriods(e,t,s,i={}){const a={includeStatuses:["confirmed","tentative"],mergePeriods:!0,...i},n=[];return this.eventStore.getEventsInRange(t,s,!1).filter(c=>!a.includeStatuses.includes(c.status)||c.status==="cancelled"?!1:c.attendees&&c.attendees.some(l=>e.includes(l.email))).forEach(c=>{n.push({start:c.start,end:c.end,eventIds:[c.id]})}),a.mergePeriods&&n.length>1?this._mergeBusyPeriods(n):n.sort((c,l)=>c.start-l.start)}getFreePeriods(e,t,s,i={}){const a={attendeeEmails:[],businessHoursOnly:!1,businessHours:{start:"09:00",end:"17:00"},excludeWeekends:!1,...i},n=[],r=a.attendeeEmails.length>0?this.getBusyPeriods(a.attendeeEmails,e,t):this._getAllBusyPeriods(e,t);let o=new Date(e);for(const c of r)o<c.start&&(c.start-o)/6e4>=s&&(!a.businessHoursOnly||this._isWithinBusinessHours(o,c.start,a))&&n.push({start:new Date(o),end:new Date(c.start)}),o=new Date(Math.max(o.getTime(),c.end.getTime()));return o<t&&(t-o)/6e4>=s&&(!a.businessHoursOnly||this._isWithinBusinessHours(o,t,a))&&n.push({start:new Date(o),end:new Date(t)}),n}_detectEventConflicts(e,t,s){const i=[];if(this._checkTimeOverlap(e,t,s.bufferMinutes)){const n=this._createTimeConflict(e,t);if(i.push(n),s.checkAttendees){const r=this._checkAttendeeConflicts(e,t);i.push(...r)}if(s.checkResources){const r=this._checkResourceConflicts(e,t);i.push(...r)}if(s.checkLocation){const r=this._checkLocationConflict(e,t);r&&i.push(r)}}return i}_checkTimeOverlap(e,t,s=0){const i=s*6e4,a=e.start.getTime()-i,n=e.end.getTime()+i,r=t.start.getTime(),o=t.end.getTime();return!(n<=r||o<=a)}_createTimeConflict(e,t){const s=new Date(Math.max(e.start.getTime(),t.start.getTime())),i=new Date(Math.min(e.end.getTime(),t.end.getTime())),a=(i-s)/6e4;let n="low";return a>=60?n="high":a>=30&&(n="medium"),e.status==="confirmed"&&t.status==="confirmed"&&(n=n==="low"?"medium":n==="medium"?"high":"critical"),{id:`conflict_${++this.conflictIdCounter}`,type:"time",severity:n,eventId:e.id,conflictingEventId:t.id,description:`Time overlap: ${e.title} conflicts with ${t.title}`,overlapStart:s,overlapEnd:i,overlapMinutes:a,metadata:{event1Title:e.title,event2Title:t.title,event1Status:e.status,event2Status:t.status}}}_checkAttendeeConflicts(e,t){const s=[];if(!e.attendees||!t.attendees)return s;const i=[];for(const a of e.attendees)for(const n of t.attendees)a.email===n.email&&i.push(a.email);if(i.length>0){let a="medium";i.some(r=>{const o=e.attendees.find(l=>l.email===r),c=t.attendees.find(l=>l.email===r);return(o==null?void 0:o.responseStatus)==="accepted"&&(c==null?void 0:c.responseStatus)==="accepted"})&&(a="critical"),s.push({id:`conflict_${++this.conflictIdCounter}`,type:"attendee",severity:a,eventId:e.id,conflictingEventId:t.id,description:`Attendee conflict: ${i.length} attendee(s) double-booked`,conflictingAttendees:i,metadata:{attendeeCount:i.length,attendeeEmails:i}})}return s}_checkResourceConflicts(e,t){var n,r;const s=[],i=((n=e.attendees)==null?void 0:n.filter(o=>o.resource))||[],a=((r=t.attendees)==null?void 0:r.filter(o=>o.resource))||[];for(const o of i)for(const c of a)o.email===c.email&&s.push({id:`conflict_${++this.conflictIdCounter}`,type:"resource",severity:"critical",eventId:e.id,conflictingEventId:t.id,description:`Resource conflict: ${o.name} is double-booked`,conflictingResource:o.email,metadata:{resourceName:o.name,resourceEmail:o.email}});return s}_checkLocationConflict(e,t){if(!e.location||!t.location)return null;const s=e.location.trim().toLowerCase(),i=t.location.trim().toLowerCase();return s===i?{id:`conflict_${++this.conflictIdCounter}`,type:"location",severity:"high",eventId:e.id,conflictingEventId:t.id,description:`Location conflict: ${e.location} is double-booked`,metadata:{location:e.location}}:null}_buildConflictSummary(e,t,s){const i={},a={};for(const n of e)i[n.type]=(i[n.type]||0)+1,a[n.severity]=(a[n.severity]||0)+1;return{hasConflicts:e.length>0,totalConflicts:e.length,conflicts:e,conflictsByType:i,conflictsBySeverity:a,affectedEventIds:Array.from(t),affectedAttendees:Array.from(s)}}_mergeBusyPeriods(e){if(e.length<=1)return e;e.sort((s,i)=>s.start-i.start);const t=[e[0]];for(let s=1;s<e.length;s++){const i=e[s],a=t[t.length-1];i.start<=a.end?(a.end=new Date(Math.max(a.end.getTime(),i.end.getTime())),a.eventIds.push(...i.eventIds)):t.push(i)}return t}_getAllBusyPeriods(e,t){return this.eventStore.getEventsInRange(e,t,!1).filter(i=>i.status!=="cancelled").map(i=>({start:i.start,end:i.end,eventIds:[i.id]})).sort((i,a)=>i.start-a.start)}_isWithinBusinessHours(e,t,s){const i=e.getHours(),a=t.getHours(),n=parseInt(s.businessHours.start.split(":")[0]),r=parseInt(s.businessHours.end.split(":")[0]);return i>=n&&a<=r}}class V{constructor(e={}){this.events=new Map,this.indices={byDate:new Map,byMonth:new Map,recurring:new Set,byCategory:new Map,byStatus:new Map},this.timezoneManager=new A,this.defaultTimezone=e.timezone||this.timezoneManager.getSystemTimezone(),this.optimizer=new Y(e.performance),this.conflictDetector=new N(this),this.isBatchMode=!1,this.batchNotifications=[],this.batchBackup=null,this.version=0,this.listeners=new Set}addEvent(e){return this.optimizer.measure("addEvent",()=>{if(e instanceof E||(e=new E(e)),this.events.has(e.id))throw new Error(`Event with id ${e.id} already exists`);return this.events.set(e.id,e),this.optimizer.cache(e.id,e,"event"),this._indexEvent(e),this.isBatchMode?this.batchNotifications.push({type:"add",event:e,version:++this.version}):this._notifyChange({type:"add",event:e,version:++this.version}),e})}updateEvent(e,t){const s=this.events.get(e);if(!s)throw new Error(`Event with id ${e} not found`);this._unindexEvent(s);const i=s.clone(t);return this.events.set(e,i),this._indexEvent(i),this._notifyChange({type:"update",event:i,oldEvent:s,version:++this.version}),i}removeEvent(e){const t=this.events.get(e);return t?(this.events.delete(e),this._unindexEvent(t),this._notifyChange({type:"remove",event:t,version:++this.version}),!0):!1}getEvent(e){const t=this.optimizer.getFromCache(e,"event");if(t)return t;const s=this.events.get(e)||null;return s&&this.optimizer.cache(e,s,"event"),s}getAllEvents(){return Array.from(this.events.values())}queryEvents(e={}){let t=Array.from(this.events.values());if(e.start||e.end){const s=e.start?new Date(e.start):null,i=e.end?new Date(e.end):null;t=t.filter(a=>!(s&&a.end<s||i&&a.start>i))}if(e.date){const s=new Date(e.date);t=t.filter(i=>i.occursOn(s))}if(e.month&&e.year){const s=`${e.year}-${String(e.month).padStart(2,"0")}`,i=this.indices.byMonth.get(s)||new Set;t=t.filter(a=>i.has(a.id))}return e.hasOwnProperty("allDay")&&(t=t.filter(s=>s.allDay===e.allDay)),e.hasOwnProperty("recurring")&&(t=t.filter(s=>s.recurring===e.recurring)),e.status&&(t=t.filter(s=>s.status===e.status)),e.categories&&e.categories.length>0&&(t=t.filter(s=>e.matchAllCategories?s.hasAllCategories(e.categories):s.hasAnyCategory(e.categories))),e.hasOwnProperty("hasAttendees")&&(t=t.filter(s=>e.hasAttendees?s.hasAttendees:!s.hasAttendees)),e.organizerEmail&&(t=t.filter(s=>s.organizer&&s.organizer.email===e.organizerEmail)),e.sort&&t.sort((s,i)=>{switch(e.sort){case"start":return s.start-i.start;case"end":return s.end-i.end;case"duration":return s.duration-i.duration;case"title":return s.title.localeCompare(i.title);default:return 0}}),t}getEventsForDate(e,t=null){t=t||this.defaultTimezone,f.getLocalDateString(e);const s=new Set,i=new Date(e);for(let l=-1;l<=1;l++){const d=new Date(i);d.setDate(d.getDate()+l);const h=f.getLocalDateString(d),b=this.indices.byDate.get(h);b&&b.forEach(D=>s.add(D))}const a=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`,n=this.indices.byMonth.get(a);n&&n.forEach(l=>s.add(l));const r=[],o=new Date(e);o.setHours(0,0,0,0);const c=new Date(e);c.setHours(23,59,59,999);for(const l of s){const d=this.events.get(l);if(d){const h=d.getStartInTimezone(t),b=d.getEndInTimezone(t);h<=c&&b>=o&&r.push(d)}}return r.sort((l,d)=>{const h=l.getStartInTimezone(t),b=d.getStartInTimezone(t),D=h-b;return D!==0?D:d.duration-l.duration})}getOverlappingEvents(e,t,s=null){const i=[],a=f.startOfDay(e),n=f.endOfDay(t),r=f.getDateRange(a,n),o=new Set;return r.forEach(c=>{const l=c.toDateString();(this.indices.byDate.get(l)||new Set).forEach(h=>{if(!o.has(h)&&h!==s){o.add(h);const b=this.events.get(h);b&&b.overlaps({start:e,end:t})&&i.push(b)}})}),i.sort((c,l)=>c.start-l.start)}hasConflicts(e,t,s=null){return this.getOverlappingEvents(e,t,s).length>0}getOverlapGroups(e,t=!0){let s=this.getEventsForDate(e);t&&(s=s.filter(n=>!n.allDay));const i=[],a=new Set;return s.forEach(n=>{if(a.has(n.id))return;const r=[n];a.add(n.id);let o=0;for(;o<r.length;){const c=r[o];s.forEach(l=>{!a.has(l.id)&&c.overlaps(l)&&(r.push(l),a.add(l.id))}),o++}i.push(r)}),i}calculateEventPositions(e){const t=new Map;if(e.length===0)return t;e.sort((a,n)=>{const r=a.start-n.start;return r!==0?r:n.end-n.start-(a.end-a.start)});const s=[];e.forEach(a=>{let n=0;for(;n<s.length&&s[n].some(c=>c.overlaps(a));)n++;s[n]||(s[n]=[]),s[n].push(a),t.set(a.id,{column:n,totalColumns:0})});const i=s.length;return t.forEach(a=>{a.totalColumns=i}),t}getEventsInRange(e,t,s=!0,i=null){typeof s=="string"&&(i=s,s=!0),i=i||this.defaultTimezone;const a=this.timezoneManager.toUTC(e,i),n=this.timezoneManager.toUTC(t,i),r=this.queryEvents({start:a,end:n,sort:"start"});if(!s)return r;const o=[];return r.forEach(c=>{if(c.recurring&&c.recurrenceRule){const l=this.expandRecurringEvent(c,e,t,i);o.push(...l)}else o.push(c)}),o.sort((c,l)=>{const d=c.getStartInTimezone(i),h=l.getStartInTimezone(i);return d-h})}expandRecurringEvent(e,t,s,i=null){if(!e.recurring||!e.recurrenceRule)return[e];i=i||this.defaultTimezone;const a=e.timeZone||i;return U.expandEvent(e,t,s).map((r,o)=>e.clone({id:`${e.id}_occurrence_${o}`,start:r.start,end:r.end,timeZone:a,metadata:{...e.metadata,recurringEventId:e.id,occurrenceIndex:o}}))}clear(){const e=this.getAllEvents();this.events.clear(),this.indices.byDate.clear(),this.indices.byMonth.clear(),this.indices.recurring.clear(),this._notifyChange({type:"clear",oldEvents:e,version:++this.version})}loadEvents(e){this.clear();for(const t of e)this.addEvent(t)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}_indexEvent(e){if(this.optimizer.shouldUseLazyIndexing(e)){this._indexEventLazy(e);return}const t=e.getStartInTimezone(e.timeZone),s=e.getEndInTimezone(e.endTimeZone||e.timeZone),i=f.startOfDay(t),a=f.endOfDay(s);f.getDateRange(i,a).forEach(o=>{const c=f.getLocalDateString(o);this.indices.byDate.has(c)||this.indices.byDate.set(c,new Set),this.indices.byDate.get(c).add(e.id)}),`${i.getFullYear()}${String(i.getMonth()+1).padStart(2,"0")}`,`${a.getFullYear()}${String(a.getMonth()+1).padStart(2,"0")}`;const r=new Date(i.getFullYear(),i.getMonth(),1);for(;r<=a;){const o=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}`;this.indices.byMonth.has(o)||this.indices.byMonth.set(o,new Set),this.indices.byMonth.get(o).add(e.id),r.setMonth(r.getMonth()+1)}e.categories&&e.categories.length>0&&e.categories.forEach(o=>{this.indices.byCategory.has(o)||this.indices.byCategory.set(o,new Set),this.indices.byCategory.get(o).add(e.id)}),e.status&&(this.indices.byStatus.has(e.status)||this.indices.byStatus.set(e.status,new Set),this.indices.byStatus.get(e.status).add(e.id)),e.recurring&&this.indices.recurring.add(e.id)}_indexEventLazy(e){this.optimizer.createLazyIndexMarkers(e);const t=e.getStartInTimezone(e.timeZone),s=e.getEndInTimezone(e.endTimeZone||e.timeZone),i=f.startOfDay(t),a=f.endOfDay(s),n=new Date(i);if(n.setDate(n.getDate()+7),f.getDateRange(i,n<a?n:a).forEach(c=>{const l=f.getLocalDateString(c);this.indices.byDate.has(l)||this.indices.byDate.set(l,new Set),this.indices.byDate.get(l).add(e.id)}),a>n){const c=new Date(a);c.setDate(c.getDate()-7),f.getDateRange(c>i?c:i,a).forEach(d=>{const h=f.getLocalDateString(d);this.indices.byDate.has(h)||this.indices.byDate.set(h,new Set),this.indices.byDate.get(h).add(e.id)})}const o=new Date(i.getFullYear(),i.getMonth(),1);for(;o<=a;){const c=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}`;this.indices.byMonth.has(c)||this.indices.byMonth.set(c,new Set),this.indices.byMonth.get(c).add(e.id),o.setMonth(o.getMonth()+1)}e.categories&&e.categories.length>0&&e.categories.forEach(c=>{this.indices.byCategory.has(c)||this.indices.byCategory.set(c,new Set),this.indices.byCategory.get(c).add(e.id)}),e.status&&(this.indices.byStatus.has(e.status)||this.indices.byStatus.set(e.status,new Set),this.indices.byStatus.get(e.status).add(e.id)),e.recurring&&this.indices.recurring.add(e.id)}_unindexEvent(e){for(const[t,s]of this.indices.byDate)s.delete(e.id),s.size===0&&this.indices.byDate.delete(t);for(const[t,s]of this.indices.byMonth)s.delete(e.id),s.size===0&&this.indices.byMonth.delete(t);this.indices.recurring.delete(e.id)}_notifyChange(e){for(const t of this.listeners)try{t(e)}catch(s){console.error("Error in EventStore listener:",s)}}getStats(){return{totalEvents:this.events.size,recurringEvents:this.indices.recurring.size,indexedDates:this.indices.byDate.size,indexedMonths:this.indices.byMonth.size,indexedCategories:this.indices.byCategory.size,indexedStatuses:this.indices.byStatus.size,version:this.version,performanceMetrics:this.optimizer.getMetrics()}}startBatch(e=!1){this.isBatchMode=!0,this.batchNotifications=[],e&&(this.batchBackup={events:new Map(this.events),indices:{byDate:new Map(Array.from(this.indices.byDate.entries()).map(([t,s])=>[t,new Set(s)])),byMonth:new Map(Array.from(this.indices.byMonth.entries()).map(([t,s])=>[t,new Set(s)])),recurring:new Set(this.indices.recurring),byCategory:new Map(Array.from(this.indices.byCategory.entries()).map(([t,s])=>[t,new Set(s)])),byStatus:new Map(Array.from(this.indices.byStatus.entries()).map(([t,s])=>[t,new Set(s)]))},version:this.version})}commitBatch(){this.isBatchMode&&(this.isBatchMode=!1,this.batchBackup=null,this.batchNotifications.length>0&&this._notifyChange({type:"batch",changes:this.batchNotifications,count:this.batchNotifications.length,version:++this.version}),this.batchNotifications=[])}rollbackBatch(){this.isBatchMode&&(this.isBatchMode=!1,this.batchBackup&&(this.events=this.batchBackup.events,this.indices=this.batchBackup.indices,this.version=this.batchBackup.version,this.batchBackup=null,this.optimizer.clearCache()),this.batchNotifications=[])}async executeBatch(e,t=!0){this.startBatch(t);try{const s=await e();return this.commitBatch(),s}catch(s){throw t&&this.rollbackBatch(),s}}addEvents(e){return this.optimizer.measure("addEvents",()=>{this.startBatch();const t=[],s=[];for(const i of e)try{t.push(this.addEvent(i))}catch(a){s.push({event:i,error:a.message})}return this.commitBatch(),s.length>0&&console.warn(`Failed to add ${s.length} events:`,s),t})}updateEvents(e){return this.optimizer.measure("updateEvents",()=>{this.startBatch();const t=[],s=[];for(const{id:i,updates:a}of e)try{t.push(this.updateEvent(i,a))}catch(n){s.push({id:i,error:n.message})}return this.commitBatch(),s.length>0&&console.warn(`Failed to update ${s.length} events:`,s),t})}removeEvents(e){return this.optimizer.measure("removeEvents",()=>{this.startBatch();let t=0;for(const s of e)this.removeEvent(s)&&t++;return this.commitBatch(),t})}getPerformanceMetrics(){return this.optimizer.getMetrics()}clearCaches(){this.optimizer.eventCache.clear(),this.optimizer.queryCache.clear(),this.optimizer.dateRangeCache.clear()}optimizeIndices(e){e||(e=new Date,e.setMonth(e.getMonth()-6)),e.toDateString();let t=0;for(const[s,i]of this.indices.byDate)if(new Date(s)<e){let n=!1;for(const r of i){const o=this.events.get(r);if(o&&o.end>=e){n=!0;break}}n||(this.indices.byDate.delete(s),t++)}return console.log(`Optimized indices: removed ${t} old date entries`),t}destroy(){this.clear(),this.optimizer.destroy(),this.listeners.clear()}checkConflicts(e,t={}){return this.conflictDetector.checkConflicts(e,t)}checkEventPairConflicts(e,t,s={}){const i=this.getEvent(e),a=this.getEvent(t);if(!i||!a)throw new Error("One or both events not found");return this.conflictDetector.checkEventPairConflicts(i,a,s)}getAllConflicts(e,t,s={}){const i=this.getEventsInRange(e,t,!1),a=[],n=new Set;for(let r=0;r<i.length;r++)for(let o=r+1;o<i.length;o++){const c=`${i[r].id}-${i[o].id}`;if(!n.has(c)){n.add(c);const l=this.conflictDetector.checkEventPairConflicts(i[r],i[o],s);a.push(...l)}}return this.conflictDetector._buildConflictSummary(a,new Set(i.map(r=>r.id)),new Set)}getBusyPeriods(e,t,s,i={}){return this.conflictDetector.getBusyPeriods(e,t,s,i)}getFreePeriods(e,t,s,i={}){return this.conflictDetector.getFreePeriods(e,t,s,i)}addEventWithConflictCheck(e,t=!0){const s=this.checkConflicts(e);if(!t&&s.hasConflicts)throw new Error(`Cannot add event: ${s.totalConflicts} conflicts detected`);return{event:this.addEvent(e),conflicts:s}}findEventsWithConflicts(e={}){const t=[],s=this.getAllEvents();for(const i of s){const a=this.checkConflicts(i,e);a.hasConflicts&&t.push({event:i,conflicts:a.conflicts})}return t}}let W=class{constructor(e={}){this.state={view:"month",currentDate:new Date,selectedEventId:null,selectedDate:null,hoveredEventId:null,hoveredDate:null,weekStartsOn:0,showWeekNumbers:!1,showWeekends:!0,fixedWeekCount:!0,timeZone:Intl.DateTimeFormat().resolvedOptions().timeZone,locale:"en-US",hourFormat:"12h",businessHours:{start:"09:00",end:"17:00"},filters:{searchTerm:"",categories:[],showAllDay:!0,showTimed:!0},isDragging:!1,isResizing:!1,isCreating:!1,isLoading:!1,loadingMessage:"",error:null,metadata:{},...e},this.listeners=new Map,this.globalListeners=new Set,this.history=[],this.historyIndex=-1,this.maxHistorySize=50}getState(){return Object.freeze({...this.state})}get(e){return this.state[e]}setState(e){const t=this.state;typeof e=="function"&&(e=e(t));const s={...t,...e,filters:e.filters?{...t.filters,...e.filters}:t.filters,businessHours:e.businessHours?{...t.businessHours,...e.businessHours}:t.businessHours,metadata:e.metadata?{...t.metadata,...e.metadata}:t.metadata};this._hasChanged(t,s)&&(this.state=s,this._addToHistory(s),this._notifyListeners(t,s))}setView(e){const t=["month","week","day","list"];if(!t.includes(e))throw new Error(`Invalid view: ${e}. Must be one of: ${t.join(", ")}`);this.setState({view:e})}setCurrentDate(e){if(e instanceof Date||(e=new Date(e)),isNaN(e.getTime()))throw new Error("Invalid date");this.setState({currentDate:e})}navigateNext(){const{view:e,currentDate:t}=this.state,s=new Date(t);switch(e){case"month":s.setMonth(s.getMonth()+1);break;case"week":s.setDate(s.getDate()+7);break;case"day":s.setDate(s.getDate()+1);break}this.setCurrentDate(s)}navigatePrevious(){const{view:e,currentDate:t}=this.state,s=new Date(t);switch(e){case"month":s.setMonth(s.getMonth()-1);break;case"week":s.setDate(s.getDate()-7);break;case"day":s.setDate(s.getDate()-1);break}this.setCurrentDate(s)}navigateToday(){this.setCurrentDate(new Date)}selectEvent(e){this.setState({selectedEventId:e})}clearEventSelection(){this.setState({selectedEventId:null})}selectDate(e){e instanceof Date||(e=new Date(e)),this.setState({selectedDate:e})}clearDateSelection(){this.setState({selectedDate:null})}setLoading(e,t=""){this.setState({isLoading:e,loadingMessage:t})}setError(e){this.setState({error:e?e instanceof Error?e.message:e:null})}updateFilters(e){this.setState({filters:{...this.state.filters,...e}})}subscribe(e){return this.globalListeners.add(e),()=>{this.globalListeners.delete(e)}}watch(e,t){const s=Array.isArray(e)?e:[e];return s.forEach(i=>{this.listeners.has(i)||this.listeners.set(i,new Set),this.listeners.get(i).add(t)}),()=>{s.forEach(i=>{const a=this.listeners.get(i);a&&(a.delete(t),a.size===0&&this.listeners.delete(i))})}}canUndo(){return this.historyIndex>0}canRedo(){return this.historyIndex<this.history.length-1}getUndoCount(){return this.historyIndex}getRedoCount(){return this.history.length-1-this.historyIndex}undo(){if(!this.canUndo())return!1;this.historyIndex--;const e=this.history[this.historyIndex],t=this.state;return this.state={...e},this._notifyListeners(t,this.state),!0}redo(){if(!this.canRedo())return!1;this.historyIndex++;const e=this.history[this.historyIndex],t=this.state;return this.state={...e},this._notifyListeners(t,this.state),!0}reset(){const e=this.history[0]||{};this.setState(e),this.history=[e],this.historyIndex=0}_hasChanged(e,t){return!this._deepEqual(e,t)}_deepEqual(e,t,s=new Set){if(e===t)return!0;if(e==null||t==null)return e===t;if(typeof e!=typeof t)return!1;if(typeof e!="object")return e===t;if(s.has(e)||s.has(t))return!1;if(s.add(e),s.add(t),Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return s.delete(e),s.delete(t),!1;for(let n=0;n<e.length;n++)if(!this._deepEqual(e[n],t[n],s))return s.delete(e),s.delete(t),!1;return s.delete(e),s.delete(t),!0}if(e instanceof Date&&t instanceof Date){const n=e.getTime()===t.getTime();return s.delete(e),s.delete(t),n}const i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return s.delete(e),s.delete(t),!1;i.sort(),a.sort();for(let n=0;n<i.length;n++)if(i[n]!==a[n])return s.delete(e),s.delete(t),!1;for(const n of i)if(!this._deepEqual(e[n],t[n],s))return s.delete(e),s.delete(t),!1;return s.delete(e),s.delete(t),!0}_addToHistory(e){this.historyIndex<this.history.length-1&&(this.history=this.history.slice(0,this.historyIndex+1)),this.history.push({...e}),this.historyIndex++,this.history.length>this.maxHistorySize&&(this.history.shift(),this.historyIndex--)}_notifyListeners(e,t){for(const s of this.globalListeners)try{s(t,e)}catch(i){console.error("Error in state listener:",i)}for(const[s,i]of this.listeners)if(e[s]!==t[s])for(const a of i)try{a(t[s],e[s],t,e)}catch(n){console.error(`Error in state listener for key "${s}":`,n)}}};class j{constructor(e={}){this.timezoneManager=new A,this.config={view:"month",date:new Date,weekStartsOn:0,locale:"en-US",timeZone:e.timeZone||this.timezoneManager.getSystemTimezone(),showWeekNumbers:!1,showWeekends:!0,fixedWeekCount:!0,businessHours:{start:"09:00",end:"17:00"},...e},this.eventStore=new V({timezone:this.config.timeZone}),this.state=new W({view:this.config.view,currentDate:this.config.date,weekStartsOn:this.config.weekStartsOn,locale:this.config.locale,timeZone:this.config.timeZone,showWeekNumbers:this.config.showWeekNumbers,showWeekends:this.config.showWeekends,fixedWeekCount:this.config.fixedWeekCount,businessHours:this.config.businessHours}),this.listeners=new Map,this.plugins=new Set,this.views=new Map,this._setupInternalListeners(),e.events&&this.setEvents(e.events)}setView(e,t=null){this.state.setView(e),t&&this.state.setCurrentDate(t),this._emit("viewChange",{view:e,date:t||this.state.get("currentDate")})}getView(){return this.state.get("view")}next(){this.state.navigateNext(),this._emit("navigate",{direction:"next",date:this.state.get("currentDate"),view:this.state.get("view")})}previous(){this.state.navigatePrevious(),this._emit("navigate",{direction:"previous",date:this.state.get("currentDate"),view:this.state.get("view")})}today(){this.state.navigateToday(),this._emit("navigate",{direction:"today",date:this.state.get("currentDate"),view:this.state.get("view")})}goToDate(e){this.state.setCurrentDate(e),this._emit("navigate",{direction:"goto",date:e,view:this.state.get("view")})}setDate(e){this.goToDate(e)}getCurrentDate(){return new Date(this.state.get("currentDate"))}addEvent(e){!(e instanceof E)&&!e.timeZone&&(e={...e,timeZone:this.config.timeZone});const t=this.eventStore.addEvent(e);return this._emit("eventAdd",{event:t}),t}updateEvent(e,t){const s=this.eventStore.getEvent(e),i=this.eventStore.updateEvent(e,t);return this._emit("eventUpdate",{event:i,oldEvent:s}),i}removeEvent(e){const t=this.eventStore.getEvent(e),s=this.eventStore.removeEvent(e);return s&&this._emit("eventRemove",{event:t}),s}deleteEvent(e){return this.removeEvent(e)}getEvent(e){return this.eventStore.getEvent(e)}getEvents(){return this.eventStore.getAllEvents()}setEvents(e){this.eventStore.loadEvents(e),this._emit("eventsSet",{events:this.getEvents()})}queryEvents(e){return this.eventStore.queryEvents(e)}getEventsForDate(e,t=null){return this.eventStore.getEventsForDate(e,t||this.config.timeZone)}getEventsInRange(e,t,s=null){return this.eventStore.getEventsInRange(e,t,!0,s||this.config.timeZone)}setTimezone(e){const t=this.timezoneManager.parseTimezone(e),s=this.config.timeZone;this.config.timeZone=t,this.eventStore.defaultTimezone=t,this.state.setState({timeZone:t}),this._emit("timezoneChange",{timezone:t,previousTimezone:s})}getTimezone(){return this.config.timeZone}setLocale(e){this.config.locale=e,this.state.setState({locale:e}),this._emit("localeChange",{locale:e})}setWeekStartsOn(e){this.config.weekStartsOn=e,this.state.setState({weekStartsOn:e}),this._emit("weekStartsOnChange",{weekStartsOn:e})}convertTimezone(e,t,s){return this.timezoneManager.convertTimezone(e,t,s)}toCalendarTimezone(e,t){return this.timezoneManager.convertTimezone(e,t,this.config.timeZone)}fromCalendarTimezone(e,t){return this.timezoneManager.convertTimezone(e,this.config.timeZone,t)}formatInTimezone(e,t=null,s={}){return this.timezoneManager.formatInTimezone(e,t||this.config.timeZone,s)}getTimezones(){return this.timezoneManager.getCommonTimezones()}getOverlapGroups(e,t=!0){return this.eventStore.getOverlapGroups(e,t)}calculateEventPositions(e){return this.eventStore.calculateEventPositions(e)}getViewData(){const e=this.state.get("view"),t=this.state.get("currentDate");switch(e){case"month":return this._getMonthViewData(t);case"week":return this._getWeekViewData(t);case"day":return this._getDayViewData(t);case"list":return this._getListViewData(t);default:return null}}_getMonthViewData(e){const t=e.getFullYear(),s=e.getMonth(),i=this.state.get("weekStartsOn"),a=this.state.get("fixedWeekCount"),n=new Date(t,s,1),r=new Date(t,s+1,0),o=f.startOfWeek(n,i),c=[];let l=new Date(o);const d=a?6:Math.ceil((r.getDate()+f.getDayOfWeek(n,i))/7);for(let h=0;h<d;h++){const b={weekNumber:f.getWeekNumber(l),days:[]};for(let D=0;D<7;D++){const k=new Date(l),S=k.getMonth()===s,M=f.isToday(k),I=k.getDay()===0||k.getDay()===6;b.days.push({date:k,dayOfMonth:k.getDate(),isCurrentMonth:S,isToday:M,isWeekend:I,events:this.getEventsForDate(k)}),l=f.addDays(l,1)}c.push(b)}return{type:"month",year:t,month:s,monthName:f.getMonthName(e,this.state.get("locale")),weeks:c,startDate:o,endDate:new Date(l.getTime()-1)}}_getWeekViewData(e){const t=this.state.get("weekStartsOn"),s=f.startOfWeek(e,t),i=f.endOfWeek(e,t),a=[],n=new Date(s);for(let r=0;r<7;r++){const o=new Date(n);a.push({date:o,dayOfMonth:o.getDate(),dayOfWeek:o.getDay(),dayName:f.getDayName(o,this.state.get("locale")),isToday:f.isToday(o),isWeekend:o.getDay()===0||o.getDay()===6,events:this.getEventsForDate(o),overlapGroups:this.eventStore.getOverlapGroups(o,!0),getEventPositions:c=>this.eventStore.calculateEventPositions(c)}),n.setDate(n.getDate()+1)}return{type:"week",weekNumber:f.getWeekNumber(s),startDate:s,endDate:i,days:a}}_getDayViewData(e){const t=this.getEventsForDate(e),s=t.filter(n=>n.allDay),i=t.filter(n=>!n.allDay),a=[];for(let n=0;n<24;n++){const r=new Date(e);r.setHours(n,0,0,0);const o=new Date(e);o.setHours(n+1,0,0,0),a.push({hour:n,time:f.formatTime(r,this.state.get("locale")),events:i.filter(c=>c.start<o&&c.end>r)})}return{type:"day",date:e,dayName:f.getDayName(e,this.state.get("locale")),isToday:f.isToday(e),allDayEvents:s,hours:a}}_getListViewData(e){const t=new Date(e);t.setHours(0,0,0,0);const s=new Date(t);s.setDate(s.getDate()+30);const i=this.getEventsInRange(t,s),a=new Map;i.forEach(r=>{const o=r.start.toDateString();a.has(o)||a.set(o,{date:new Date(r.start),events:[]}),a.get(o).events.push(r)});const n=Array.from(a.values()).sort((r,o)=>r.date-o.date).map(r=>({...r,dayName:f.getDayName(r.date,this.state.get("locale")),isToday:f.isToday(r.date)}));return{type:"list",startDate:t,endDate:s,days:n,totalEvents:i.length}}selectEvent(e){const t=this.getEvent(e);t&&(this.state.selectEvent(e),this._emit("eventSelect",{event:t}))}clearEventSelection(){const e=this.state.get("selectedEventId");this.state.clearEventSelection(),e&&this._emit("eventDeselect",{eventId:e})}selectDate(e){this.state.selectDate(e),this._emit("dateSelect",{date:e})}clearDateSelection(){const e=this.state.get("selectedDate");this.state.clearDateSelection(),e&&this._emit("dateDeselect",{date:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}off(e,t){const s=this.listeners.get(e);s&&(s.delete(t),s.size===0&&this.listeners.delete(e))}_emit(e,t){const s=this.listeners.get(e);s&&s.forEach(i=>{try{i(t)}catch(a){console.error(`Error in event listener for "${e}":`,a)}})}_setupInternalListeners(){this.state.subscribe((e,t)=>{this._emit("stateChange",{newState:e,oldState:t})}),this.eventStore.subscribe(e=>{this._emit("eventStoreChange",e)})}use(e){if(this.plugins.has(e)){console.warn("Plugin already installed");return}if(typeof e.install=="function")e.install(this),this.plugins.add(e);else throw new Error("Plugin must have an install method")}destroy(){this.listeners.clear(),this.eventStore.clear(),this.plugins.forEach(e=>{typeof e.uninstall=="function"&&e.uninstall(this)}),this.plugins.clear(),this._emit("destroy")}}class L{constructor(){this.events=new Map,this.wildcardHandlers=new Set}on(e,t,s={}){const{once:i=!1,priority:a=0}=s;if(e.includes("*")){const o={pattern:e,handler:t,once:i,priority:a};return this.wildcardHandlers.add(o),()=>this.wildcardHandlers.delete(o)}this.events.has(e)||this.events.set(e,[]);const n={handler:t,once:i,priority:a},r=this.events.get(e);return r.push(n),r.sort((o,c)=>c.priority-o.priority),()=>{const o=r.indexOf(n);o>-1&&r.splice(o,1)}}once(e,t,s={}){return this.on(e,t,{...s,once:!0})}off(e,t){if(!this.events.has(e))return;const s=this.events.get(e),i=s.findIndex(a=>a.handler===t);i>-1&&s.splice(i,1),s.length===0&&this.events.delete(e)}async emit(e,t){const s=[];if(this.events.has(e)){const a=[...this.events.get(e)];for(const n of a){const{handler:r,once:o}=n;o&&this.off(e,r);try{const c=r(t,e);c instanceof Promise&&s.push(c)}catch(c){console.error(`Error in event handler for ${e}:`,c)}}}const i=[];for(const a of[...this.wildcardHandlers])if(this.matchesPattern(e,a.pattern)){const{handler:n,once:r}=a;r&&i.push(a);try{const o=n(t,e);o instanceof Promise&&s.push(o)}catch(o){console.error(`Error in wildcard handler for ${e}:`,o)}}return i.forEach(a=>this.wildcardHandlers.delete(a)),Promise.all(s)}matchesPattern(e,t){return new RegExp("^"+t.replace(/\*/g,".*")+"$").test(e)}clear(){this.events.clear(),this.wildcardHandlers.clear()}getEventNames(){return Array.from(this.events.keys())}getHandlerCount(e){return this.events.has(e)?this.events.get(e).length:0}}const m=new L;class F{constructor(e={}){this.calendar=new j({view:e.view||"month",date:e.date||new Date,weekStartsOn:e.weekStartsOn??0,locale:e.locale||"en-US",timeZone:e.timeZone||Intl.DateTimeFormat().resolvedOptions().timeZone,...e}),this.state={view:this.calendar.getView(),currentDate:this.calendar.getCurrentDate(),events:[],selectedEvent:null,selectedDate:null,loading:!1,error:null,config:{...e}},this.subscribers=new Set,this.subscribe=this.subscribe.bind(this),this.unsubscribe=this.unsubscribe.bind(this),this.setState=this.setState.bind(this)}getState(){return{...this.state}}setState(e,t={}){const{silent:s=!1}=t,i={...this.state};return this.state={...this.state,...e},s||(this.notifySubscribers(i,this.state),this.emitStateChange(i,this.state)),this.state}subscribe(e){return this.subscribers.add(e),()=>this.unsubscribe(e)}unsubscribe(e){this.subscribers.delete(e)}notifySubscribers(e,t){this.subscribers.forEach(s=>{try{s(t,e)}catch(i){console.error("Error in state subscriber:",i)}})}emitStateChange(e,t){const s=Object.keys(t).filter(i=>e[i]!==t[i]);s.forEach(i=>{m.emit(`state:${i}:changed`,{oldValue:e[i],newValue:t[i],state:t})}),s.length>0&&m.emit("state:changed",{oldState:e,newState:t,changedKeys:s})}setView(e){this.calendar.setView(e),this.setState({view:e}),m.emit("view:changed",{view:e})}getView(){return this.state.view}setDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("date:changed",{date:this.state.currentDate})}getCurrentDate(){return this.state.currentDate}next(){this.calendar.next(),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:next",{date:this.state.currentDate})}previous(){this.calendar.previous(),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:previous",{date:this.state.currentDate})}today(){this.calendar.today(),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:today",{date:this.state.currentDate})}goToDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),m.emit("navigation:goto",{date:this.state.currentDate})}addEvent(e){const t=this.calendar.addEvent(e);if(!t)return console.error("Failed to add event to calendar"),m.emit("event:error",{action:"add",event:e,error:"Failed to add event"}),null;const s=[...this.state.events,t];return this.setState({events:s}),m.emit("event:added",{event:t}),t}updateEvent(e,t){const s=this.calendar.updateEvent(e,t);if(!s)return console.error(`Failed to update event: ${e}`),m.emit("event:error",{action:"update",eventId:e,updates:t,error:"Event not found in calendar"}),null;const i=this.state.events.findIndex(n=>n.id===e);if(i===-1)return console.error(`Event ${e} not found in state`),m.emit("event:error",{action:"update",eventId:e,error:"Event not found in state"}),null;const a=[...this.state.events];return a[i]=s,this.setState({events:a}),m.emit("event:updated",{event:s}),s}deleteEvent(e){if(!this.calendar.removeEvent(e))return console.error(`Failed to delete event: ${e}`),m.emit("event:error",{action:"delete",eventId:e,error:"Event not found"}),!1;const s=this.state.events.filter(i=>i.id!==e);return this.setState({events:s}),m.emit("event:deleted",{eventId:e}),!0}getEvents(){return this.calendar.getEvents()}getEventsForDate(e){return this.calendar.getEventsForDate(e)}getEventsInRange(e,t){return this.calendar.getEventsInRange(e,t)}getViewData(){const e=this.calendar.getViewData();return this.enrichViewData(e)}enrichViewData(e){var s;const t=(s=this.state.selectedDate)==null?void 0:s.toDateString();if(e.weeks&&(e.weeks=e.weeks.map(i=>({...i,days:i.days.map(a=>{const n=new Date(a.date);return{...a,isSelected:n.toDateString()===t,events:a.events||this.getEventsForDate(n)}})}))),e.days&&(e.days=e.days.map(i=>{const a=new Date(i.date);return{...i,isSelected:a.toDateString()===t,events:i.events||this.getEventsForDate(a)}})),e.date&&!e.days&&!e.weeks){const i=new Date(e.date);e.isSelected=i.toDateString()===t,e.events=e.events||this.getEventsForDate(i)}return e}selectEvent(e){this.setState({selectedEvent:e}),m.emit("event:selected",{event:e})}selectEventById(e){const t=this.state.events.find(s=>s.id===e);t&&this.selectEvent(t)}deselectEvent(){this.setState({selectedEvent:null}),m.emit("event:deselected",{})}selectDate(e){this.setState({selectedDate:e}),m.emit("date:selected",{date:e})}deselectDate(){this.setState({selectedDate:null}),m.emit("date:deselected",{})}isToday(e){const t=new Date;return e.toDateString()===t.toDateString()}isSelectedDate(e){return this.state.selectedDate&&e.toDateString()===this.state.selectedDate.toDateString()}isWeekend(e){const t=e.getDay();return t===0||t===6}setLoading(e){this.setState({loading:e})}setError(e){this.setState({error:e}),e&&m.emit("error",{error:e})}clearError(){this.setState({error:null})}updateConfig(e){this.setState({config:{...this.state.config,...e}}),e.weekStartsOn!==void 0&&this.calendar.setWeekStartsOn(e.weekStartsOn),e.locale!==void 0&&this.calendar.setLocale(e.locale),e.timeZone!==void 0&&this.calendar.setTimezone(e.timeZone)}destroy(){this.subscribers.clear(),this.state=null,this.calendar=null}}class y extends f{static formatDate(e,t="default",s="en-US"){if(!e)return"";const i={default:{year:"numeric",month:"long",day:"numeric"},short:{year:"numeric",month:"short",day:"numeric"},long:{weekday:"long",year:"numeric",month:"long",day:"numeric"},month:{year:"numeric",month:"long"},monthShort:{year:"numeric",month:"short"},day:{weekday:"long",day:"numeric"},dayShort:{weekday:"short",day:"numeric"},time:{hour:"numeric",minute:"2-digit"},timeShort:{hour:"numeric"},datetime:{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}},a=i[t]||i.default;return new Intl.DateTimeFormat(s,a).format(e)}static formatTime(e,t=!0,s=!1,i="en-US"){if(!e)return"";const a={hour:"numeric",minute:t?"2-digit":void 0,hour12:!s};return new Intl.DateTimeFormat(i,a).format(e)}static formatDateRange(e,t,s="en-US"){if(!e)return"";if(!t||this.isSameDay(e,t))return this.formatDate(e,"default",s);const i=this.isSameYear(e,t)?"short":"default";return`${this.formatDate(e,i,s)} - ${this.formatDate(t,"default",s)}`}static formatTimeRange(e,t,s="en-US"){if(!e)return"";const i=this.formatTime(e,!0,!1,s);if(!t)return i;const a=this.formatTime(t,!0,!1,s);return`${i} - ${a}`}static getRelativeTime(e,t=new Date,s="en-US"){const i=new Intl.RelativeTimeFormat(s,{numeric:"auto"}),a=e-t,n=Math.floor(a/1e3),r=Math.floor(n/60),o=Math.floor(r/60),c=Math.floor(o/24),l=Math.floor(c/7),d=Math.floor(c/30),h=Math.floor(c/365);return Math.abs(n)<60?i.format(n,"second"):Math.abs(r)<60?i.format(r,"minute"):Math.abs(o)<24?i.format(o,"hour"):Math.abs(c)<7?i.format(c,"day"):Math.abs(l)<4?i.format(l,"week"):Math.abs(d)<12?i.format(d,"month"):i.format(h,"year")}static isToday(e){const t=new Date;return this.isSameDay(e,t)}static isPast(e){return e<new Date}static isFuture(e){return e>new Date}static getWeekNumber(e){const t=new Date(e.getFullYear(),0,1),s=(e-t)/864e5;return Math.ceil((s+t.getDay()+1)/7)}static getDayAbbreviation(e,t="en-US"){const s=new Date(2024,0,7+e);return new Intl.DateTimeFormat(t,{weekday:"short"}).format(s)}static getMonthName(e,t="long",s="en-US"){const i=new Date(2024,e,1);return new Intl.DateTimeFormat(s,{month:t}).format(i)}static parseTimeString(e,t=new Date){const s=new Date(t),[i,a]=e.split(/\s+/),[n,r]=i.split(":").map(Number);let o=n;return a&&(a.toLowerCase()==="pm"&&n<12?o=n+12:a.toLowerCase()==="am"&&n===12&&(o=0)),s.setHours(o,r||0,0,0),s}}class T{static createElement(e,t={},s=[]){const i=document.createElement(e);return Object.entries(t).forEach(([a,n])=>{if(a==="className")i.className=n;else if(a==="style"&&typeof n=="object")Object.assign(i.style,n);else if(a.startsWith("data-"))i.setAttribute(a,n);else if(a.startsWith("on")&&typeof n=="function"){const r=a.slice(2).toLowerCase();i.addEventListener(r,n)}else i[a]=n}),s.forEach(a=>{typeof a=="string"?i.appendChild(document.createTextNode(a)):a instanceof Node&&i.appendChild(a)}),i}static addEventListeners(e,t){return Object.entries(t).forEach(([s,i])=>{e.addEventListener(s,i)}),()=>{Object.entries(t).forEach(([s,i])=>{e.removeEventListener(s,i)})}}static delegate(e,t,s,i){const a=n=>{const r=n.target.closest(t);r&&e.contains(r)&&i.call(r,n)};return e.addEventListener(s,a),()=>e.removeEventListener(s,a)}static getPosition(e){const t=e.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX,bottom:t.bottom+window.scrollY,right:t.right+window.scrollX,width:t.width,height:t.height}}static isInViewport(e,t=0){const s=e.getBoundingClientRect();return s.top>=-t&&s.left>=-t&&s.bottom<=(window.innerHeight||document.documentElement.clientHeight)+t&&s.right<=(window.innerWidth||document.documentElement.clientWidth)+t}static scrollToElement(e,t={}){const{behavior:s="smooth",block:i="start",inline:a="nearest"}=t;e.scrollIntoView({behavior:s,block:i,inline:a})}static getStyle(e,t){return window.getComputedStyle(e).getPropertyValue(t)}static setStyles(e,t){Object.assign(e.style,t)}static async animateClass(e,t,s=300){e.classList.add(t),await this.wait(s),e.classList.remove(t)}static waitForAnimation(e,t="animationend"){return new Promise(s=>{const i=()=>{e.removeEventListener(t,i),s()};e.addEventListener(t,i)})}static wait(e){return new Promise(t=>setTimeout(t,e))}static parseHTML(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}static escapeHTML(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}static debounce(e,t=250){let s;return function(...a){const n=()=>{clearTimeout(s),e(...a)};clearTimeout(s),s=setTimeout(n,t)}}static throttle(e,t=250){let s;return function(...i){s||(e.apply(this,i),s=!0,setTimeout(()=>s=!1,t))}}static closest(e,t){return e.closest(t)}static parents(e,t){const s=[];let i=e.parentElement;for(;i;)i.matches(t)&&s.push(i),i=i.parentElement;return s}static getOuterDimensions(e){const t=window.getComputedStyle(e),s={top:parseInt(t.marginTop),right:parseInt(t.marginRight),bottom:parseInt(t.marginBottom),left:parseInt(t.marginLeft)};return{width:e.offsetWidth+s.left+s.right,height:e.offsetHeight+s.top+s.bottom,margin:s}}static cloneWithEvents(e,t=!0){return e.cloneNode(t)}static trapFocus(e){const t=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(t.length===0)return e.setAttribute("tabindex","-1"),e.focus(),()=>e.removeAttribute("tabindex");const s=t[0],i=t[t.length-1],a=n=>{n.key==="Tab"&&(n.shiftKey?document.activeElement===s&&(i==null||i.focus(),n.preventDefault()):document.activeElement===i&&(s==null||s.focus(),n.preventDefault()))};return e.addEventListener("keydown",a),s==null||s.focus(),()=>e.removeEventListener("keydown",a)}}class g{static getCSSVariable(e,t=document.documentElement){return getComputedStyle(t).getPropertyValue(e).trim()}static setCSSVariables(e,t=document.documentElement){Object.entries(e).forEach(([s,i])=>{t.style.setProperty(s,i)})}static getBaseStyles(){return`
16
16
  :host {
17
17
  /* Apply CSS variables */
18
18
  ${Object.entries(this.cssVariables).map(([e,t])=>`${e}: ${t};`).join(`