/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{a as b}from"./6EBOSWUC.js";import{a as f,b as g}from"./D2PYOSUX.js";import"./GZRB3PDY.js";var M=new Date,T=M.toISOString(),v=365,y=v,R={groupDateRange:y,startDate:T},S=(t,r,e)=>{let o=[],n=e.create(t);for(let l=0;l<=r;l++)n=e.increase(n),o.push(e.formatToIsoDateString(n));return o},w=(t,r,e,o)=>{let n=new Map,l=S(r,e,o);return t.map(c=>{let{label:s}=c,a=g(s),u=l.map(m=>{let d=`${m}-${s}`,i=n.get(d);return i||(i=o.isoToTimeZone(m,s),n.set(d,i),i)});return{...c,continent:a,isRegularContinent:a!==f,dates:u}})},J=(t,r,e)=>t.length===r.length&&t.every((o,n)=>e.same(o,r[n])),Z=(t,r=5)=>{let e=t.filter(({label:n})=>g(n)!==f);if(e.length===0)return[0];let o=e.map(n=>t.indexOf(n));return x(o,r)};function x(t,r=5){let e=t.length;if(e<=r)return t;let o=Math.min(e-2,r-2),n=(e-1)/(o+1);return[t[0],...Array.from({length:o},(l,c)=>t[Math.round((c+1)*n)]),t[e-1]]}async function G(t){let{groupDateRange:r,startDate:e,dateEngine:o}={...R,...t},n=[];if(!o)throw new Error("dateEngine is required");let l=b.map(s=>({label:s})),c=w(l,e,r,o);for(let s of c){let{label:a,continent:u,dates:m}=s;if(s.visited)continue;s.visited=!0;let d={labelIdx:[],tzs:[{label:a}]};for(let i of c.filter(p=>!p.visited)){let{label:p,continent:h,isRegularContinent:z,dates:D}=i;if((u===h||!z)&&J(m,D,o)){let I={label:p};d.tzs.push(I),i.visited=!0}}n.push(d)}return n.map(s=>(s.tzs=s.tzs.sort((a,u)=>a.label.localeCompare(u.label)),{labelTzIdx:Z(s.tzs,7),tzs:s.tzs.map(a=>a.label)})).sort((s,a)=>a.tzs.length-s.tzs.length)}export{G as groupByOffset};
