import*as TextUtils from"../text_utils/text_utils.js";import{CSSLocation}from"./CSSModel.js";export class CSSMediaQuery{constructor(e){this._active=e.active,this._expressions=[];for(let t=0;t<e.expressions.length;++t)this._expressions.push(CSSMediaQueryExpression.parsePayload(e.expressions[t]))}static parsePayload(e){return new CSSMediaQuery(e)}active(){return this._active}expressions(){return this._expressions}}export class CSSMediaQueryExpression{constructor(e){this._value=e.value,this._unit=e.unit,this._feature=e.feature,this._valueRange=e.valueRange?TextUtils.TextRange.TextRange.fromObject(e.valueRange):null,this._computedLength=e.computedLength||null}static parsePayload(e){return new CSSMediaQueryExpression(e)}value(){return this._value}unit(){return this._unit}feature(){return this._feature}valueRange(){return this._valueRange}computedLength(){return this._computedLength}}export class CSSMedia{constructor(e,t){this._cssModel=e,this._reinitialize(t)}static parsePayload(e,t){return new CSSMedia(e,t)}static parseMediaArrayPayload(e,t){const i=[];for(let r=0;r<t.length;++r)i.push(CSSMedia.parsePayload(e,t[r]));return i}_reinitialize(e){if(this.text=e.text,this.source=e.source,this.sourceURL=e.sourceURL||"",this.range=e.range?TextUtils.TextRange.TextRange.fromObject(e.range):null,this.styleSheetId=e.styleSheetId,this.mediaList=null,e.mediaList){this.mediaList=[];for(let t=0;t<e.mediaList.length;++t)this.mediaList.push(CSSMediaQuery.parsePayload(e.mediaList[t]))}}rebase(e){this.styleSheetId===e.styleSheetId&&this.range&&(e.oldRange.equal(this.range)?this._reinitialize(e.payload):this.range=this.range.rebaseAfterTextEdit(e.oldRange,e.newRange))}equal(e){return!!(this.styleSheetId&&this.range&&e.range)&&(this.styleSheetId===e.styleSheetId&&this.range.equal(e.range))}active(){if(!this.mediaList)return!0;for(let e=0;e<this.mediaList.length;++e)if(this.mediaList[e].active())return!0;return!1}lineNumberInSource(){if(!this.range)return;const e=this.header();return e?e.lineNumberInSource(this.range.startLine):void 0}columnNumberInSource(){if(!this.range)return;const e=this.header();return e?e.columnNumberInSource(this.range.startLine,this.range.startColumn):void 0}header(){return this.styleSheetId?this._cssModel.styleSheetHeaderForId(this.styleSheetId):null}rawLocation(){const e=this.header();if(!e||void 0===this.lineNumberInSource())return null;const t=Number(this.lineNumberInSource());return new CSSLocation(e,t,this.columnNumberInSource())}}export const Source={LINKED_SHEET:"linkedSheet",INLINE_SHEET:"inlineSheet",MEDIA_RULE:"mediaRule",IMPORT_RULE:"importRule"};