import { Property } from './Property.js';
import { Headers } from '../lib/headers/Headers.js';
/**
 * An array that specializes in keeping HTTP headers data.
 * Unlike the `Headers` class, this can be serialized with the state.
 */
export class HeadersArray extends Array {
    static fromHeaders(headersStr) {
        const headers = new Headers(headersStr);
        const array = new HeadersArray();
        headers.forEach((value, name, enabled) => {
            const p = Property.String(name, value, enabled);
            array.push(p);
        });
        return array;
    }
    static from(arrayLike) {
        const arr = Array.from(arrayLike);
        const result = new HeadersArray();
        arr.forEach((item) => result.push(new Property(item)));
        return result;
    }
    toHeaders() {
        const headers = new Headers();
        this.forEach((item) => {
            const header = item;
            headers.append(header.name, header.value, header.enabled);
        });
        return headers;
    }
    /**
     * Overrides native toString to generate the headers string.
     * @returns HTTP headers string.
     */
    toString() {
        const headers = new Headers();
        this.forEach((item) => {
            const header = item;
            headers.append(header.name, header.value, header.enabled);
        });
        return headers.toString();
    }
    /**
     * @returns The HTTP headers string with `#` marks when the header is disabled
     */
    toRawString() {
        const headers = new Headers();
        this.forEach((item) => {
            const header = item;
            headers.append(header.name, header.value, header.enabled);
        });
        return headers.toRawString();
    }
    toJSON() {
        return [...this.map((i) => i.toJSON())];
    }
}
//# sourceMappingURL=HeadersArray.js.map