export class Cookie{constructor(t,e,i,r){this._name=t,this._value=e,this._type=i,this._attributes={},this._size=0,this._priority=r||"Medium",this._cookieLine=null}static fromProtocolCookie(t){const e=new Cookie(t.name,t.value,null,t.priority);return e.addAttribute("domain",t.domain),e.addAttribute("path",t.path),t.expires&&e.addAttribute("expires",1e3*t.expires),t.httpOnly&&e.addAttribute("httpOnly"),t.secure&&e.addAttribute("secure"),t.sameSite&&e.addAttribute("sameSite",t.sameSite),t.sameParty&&e.addAttribute("sameParty"),"sourcePort"in t&&e.addAttribute("sourcePort",t.sourcePort),"sourceScheme"in t&&e.addAttribute("sourceScheme",t.sourceScheme),e.setSize(t.size),e}key(){return(this.domain()||"-")+" "+this.name()+" "+(this.path()||"-")}name(){return this._name}value(){return this._value}type(){return this._type}httpOnly(){return"httponly"in this._attributes}secure(){return"secure"in this._attributes}sameSite(){return this._attributes.samesite}sameParty(){return"sameparty"in this._attributes}priority(){return this._priority}session(){return!("expires"in this._attributes||"max-age"in this._attributes)}path(){return this._attributes.path}domain(){return this._attributes.domain}expires(){return this._attributes.expires}maxAge(){return this._attributes["max-age"]}sourcePort(){return this._attributes.sourceport}sourceScheme(){return this._attributes.sourcescheme}size(){return this._size}url(){if(!this.domain()||!this.path())return null;let t="";const e=this.sourcePort();return e&&80!==e&&443!==e&&(t=`:${this.sourcePort()}`),(this.secure()?"https://":"http://")+this.domain()+t+this.path()}setSize(t){this._size=t}expiresDate(t){return this.maxAge()?new Date(t.getTime()+1e3*this.maxAge()):this.expires()?new Date(this.expires()):null}addAttribute(t,e){const i=t.toLowerCase();if("priority"===i)this._priority=e;else this._attributes[i]=e}setCookieLine(t){this._cookieLine=t}getCookieLine(){return this._cookieLine}matchesSecurityOrigin(t){const e=new URL(t).hostname;return Cookie.isDomainMatch(this.domain(),e)}static isDomainMatch(t,e){return e===t||!(!t||"."!==t[0])&&(t.substr(1)===e||e.length>t.length&&e.endsWith(t))}}export const Type={Request:0,Response:1};export const Attributes={Name:"name",Value:"value",Size:"size",Domain:"domain",Path:"path",Expires:"expires",HttpOnly:"httpOnly",Secure:"secure",SameSite:"sameSite",SameParty:"sameParty",SourceScheme:"sourceScheme",SourcePort:"sourcePort",Priority:"priority"};export class CookieReference{constructor(t,e,i,r){this._name=t,this._domain=e,this._path=i,this._contextUrl=r}domain(){return this._domain}contextUrl(){return this._contextUrl}}