"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Types_1 = require("../../Types");
var SnapMatch_1 = require("./SnapMatch");
var ig_gfx_core_1 = require("@intelligentgraphics/ig.gfx.core");
/**
 * Class representing matching of child - parent relations
 */
var StrongChildMatch = /** @class */ (function (_super) {
    tslib_1.__extends(StrongChildMatch, _super);
    /** The constructor */
    function StrongChildMatch(child, parent, childId, parentId) {
        var _this = _super.call(this, child, parent, childId, parentId) || this;
        _this.snapMode = Types_1.SnapMode.Strong;
        _this.isCoreMatch = StrongChildMatch.isCoreMatch(child, parent);
        _this.canIntersectSnappedTo = true;
        return _this;
    }
    StrongChildMatch.prototype.isValid = function () {
        if (!this.isCoreMatch) {
            return false;
        }
        if (this.xzDistance > SnapMatch_1.SnapMatch.maxDistance * 2) {
            return false;
        }
        return true;
    };
    StrongChildMatch.isCoreMatch = function (child, parent) {
        var matchingTypes = parent.type === "Child" && child.type === "Origin";
        if (matchingTypes) {
            var tRegExp = ig_gfx_core_1.CoreUtils.createSaneRegExp(parent.foreign);
            if (tRegExp.test(child.key)) {
                var rxChild = ig_gfx_core_1.CoreUtils.createSaneRegExp(child.foreign);
                if (rxChild.test(parent.key)) {
                    return true;
                }
            }
        }
        return false;
    };
    return StrongChildMatch;
}(SnapMatch_1.SnapMatch));
exports.StrongChildMatch = StrongChildMatch;
