"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 Popup
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.HTMLElementPopup = void 0;
const React = require("react");
const core_react_1 = require("@itwin/core-react");
const CursorPopup_1 = require("../cursor/cursorpopup/CursorPopup");
const PopupManager_1 = require("./PopupManager");
const PositionPopup_1 = require("./PositionPopup");
const MessageSpan_1 = require("../messages/MessageSpan");
/** Popup component for HTMLElement
 * @alpha
 */
class HTMLElementPopup extends React.PureComponent {
    constructor() {
        super(...arguments);
        /** @internal */
        this.state = {
            size: new core_react_1.Size(-1, -1),
        };
        this._onSizeKnown = (newSize) => {
            // istanbul ignore else
            if (!this.state.size.equals(newSize))
                this.setState({ size: core_react_1.Size.create(newSize) });
        };
    }
    render() {
        let point = PopupManager_1.PopupManager.getPopupPosition(this.props.el, this.props.pt, new core_react_1.Point(), this.state.size);
        const popupRect = CursorPopup_1.CursorPopup.getPopupRect(point, this.props.offset, this.state.size, this.props.relativePosition);
        point = new core_react_1.Point(popupRect.left, popupRect.top);
        return (React.createElement(PositionPopup_1.PositionPopup, { key: this.props.id, className: "uifw-no-border", point: point, onSizeKnown: this._onSizeKnown },
            React.createElement(core_react_1.DivWithOutsideClick, { onOutsideClick: this.props.onCancel },
                React.createElement(MessageSpan_1.MessageDiv, { message: this.props.element }))));
    }
}
exports.HTMLElementPopup = HTMLElementPopup;
//# sourceMappingURL=HTMLElementPopup.js.map