"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttributeResolutionDirectiveSet = void 0;
class AttributeResolutionDirectiveSet {
    constructor(set) {
        if (set) {
            this.set = new Set(set);
        }
    }
    copy() {
        const result = new AttributeResolutionDirectiveSet();
        if (this.set) {
            result.set = new Set(this.set);
        }
        if (this.setRemoved) {
            result.setRemoved = new Set(this.setRemoved);
        }
        result.sortedTag = this.sortedTag;
        return result;
    }
    has(directive) {
        if (this.set) {
            return this.set.has(directive);
        }
        return false;
    }
    add(directive) {
        if (!this.set) {
            this.set = new Set();
        }
        // once explicitly removed from a set, never put it back.
        if (this.setRemoved && this.setRemoved.has(directive)) {
            return;
        }
        this.set.add(directive);
        this.sortedTag = undefined;
    }
    delete(directive) {
        if (!this.setRemoved) {
            this.setRemoved = new Set();
        }
        this.setRemoved.add(directive);
        if (this.set) {
            if (this.set.has(directive)) {
                this.set.delete(directive);
            }
        }
        this.sortedTag = undefined;
    }
    merge(directives) {
        if (directives) {
            if (directives.setRemoved) {
                // copy over the removed list first
                directives.setRemoved.forEach((d) => {
                    this.delete(d);
                });
            }
            if (directives.set) {
                directives.set.forEach((d) => {
                    this.add(d);
                });
            }
            this.sortedTag = undefined;
        }
    }
    getTag() {
        if (this.sortedTag === undefined) {
            if (this.set && this.set.size) {
                this.sortedTag = '';
                const sorted = Array.from(this.set)
                    .sort();
                sorted.forEach((d) => {
                    this.sortedTag += `-${d}`;
                });
            }
        }
        if (this.sortedTag) {
            return this.sortedTag;
        }
        return '';
    }
}
exports.AttributeResolutionDirectiveSet = AttributeResolutionDirectiveSet;
//# sourceMappingURL=AttributeResolutionDirectiveSet.js.map