"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Searchable_1 = require("./Searchable");
var Package_1 = require("./Package");
var Tag = /** @class */ (function (_super) {
    __extends(Tag, _super);
    function Tag(value) {
        var _this = _super.call(this) || this;
        _this.value = value;
        var alreadyCreatedTag = Tag.allTags.find(function (tag) { return tag.value === _this.value; });
        if (alreadyCreatedTag) {
            return alreadyCreatedTag;
        }
        else {
            Tag.allTags.push(_this);
        }
        return _this;
    }
    Tag.prototype.matches = function (other, packages) {
        var _this = this;
        if (other instanceof Tag && other.value === this.value) {
            return true;
        }
        if (other instanceof Package_1.default &&
            other.tags !== undefined &&
            other.tags.some(function (tag) { return tag.value === _this.value; })) {
            return true;
        }
        for (var _i = 0, packages_1 = packages; _i < packages_1.length; _i++) {
            var item = packages_1[_i];
            if (item.matches(this) && item.matches(other)) {
                return true;
            }
        }
        return false;
    };
    Tag.prototype.toString = function () {
        return this.value;
    };
    Tag.prototype.getSearchItemText = function () {
        return ["#" + this.value, "keyword:" + this.value, "tag:" + this.value];
    };
    Tag.allTags = [];
    return Tag;
}(Searchable_1.default));
exports.Tag = Tag;
