"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Tiles
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.tileTreeReferenceFromRenderGraphic = tileTreeReferenceFromRenderGraphic;
const core_bentley_1 = require("@itwin/core-bentley");
const internal_1 = require("./internal");
const core_geometry_1 = require("@itwin/core-geometry");
const IModelApp_1 = require("../IModelApp");
class GraphicTile extends internal_1.Tile {
    constructor(tree, graphic) {
        const range = new core_geometry_1.Range3d();
        graphic.unionRange(range);
        super({
            contentId: tree.id,
            range,
            maximumSize: 1,
        }, tree);
        this.setGraphic(graphic);
    }
    _loadChildren(resolve) {
        resolve(undefined);
    }
    async requestContent() {
        return Promise.resolve(this.tree.id);
    }
    async readContent() {
        return {};
    }
    get channel() {
        return IModelApp_1.IModelApp.tileAdmin.channels.getForHttp("render-graphic-tile");
    }
}
class GraphicTree extends internal_1.TileTree {
    _rootTile;
    _viewFlagOverrides;
    constructor(args) {
        super({
            iModel: args.iModel,
            id: args.id,
            modelId: args.modelId,
            location: core_geometry_1.Transform.createIdentity(),
            priority: internal_1.TileLoadPriority.Primary,
        });
        this._rootTile = new GraphicTile(this, args.graphic);
        this._viewFlagOverrides = args.viewFlags ?? {};
    }
    get rootTile() { return this._rootTile; }
    // ###TODO rm TileTree.is3d - only iModel tiles care about it.
    get is3d() { return true; }
    get maxDepth() { return undefined; }
    get viewFlagOverrides() { return this._viewFlagOverrides; }
    _selectTiles(args) {
        args.markUsed(this.rootTile);
        return [this.rootTile];
    }
    prune() { }
    draw(args) {
        const tiles = this.selectTiles(args);
        for (const tile of tiles)
            tile.drawGraphics(args);
        args.drawGraphics();
    }
}
class Supplier {
    compareTileTreeIds(lhs, rhs) {
        return (0, core_bentley_1.compareStrings)(lhs.id, rhs.id);
    }
    async createTileTree(id) {
        return Promise.resolve(new GraphicTree(id));
    }
}
const supplier = new Supplier();
class GraphicRef extends internal_1.TileTreeReference {
    _owner;
    _modelId;
    _getToolTip;
    _planarClipMaskPriority;
    constructor(args) {
        super();
        this._owner = args.iModel.tiles.getTileTreeOwner(args, supplier);
        this._modelId = args.modelId;
        this._getToolTip = args.getToolTip;
        this._planarClipMaskPriority = args.planarClipMaskPriority;
    }
    get treeOwner() { return this._owner; }
    get planarClipMaskPriority() { return this._planarClipMaskPriority ?? super.planarClipMaskPriority; }
    canSupplyToolTip(hit) {
        return undefined !== this._getToolTip && this._modelId === hit.modelId;
    }
    async getToolTip(hit) {
        if (this._getToolTip && this._modelId === hit.modelId) {
            return this._getToolTip(hit);
        }
        return undefined;
    }
}
/** @internal */
function tileTreeReferenceFromRenderGraphic(args) {
    return new GraphicRef({ ...args, id: core_bentley_1.Guid.createValue() });
}
//# sourceMappingURL=RenderGraphicTileTree.js.map