/*---------------------------------------------------------------------------------------------
 * 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
 */
import * as React from "react";
import { PropertyValueFormat } from "@itwin/appui-abstract";
import { EditorContainer } from "@itwin/components-react";
import { DivWithOutsideClick } from "@itwin/core-react";
import { PopupManager } from "./PopupManager.js";
import { PositionPopup, PositionPopupContent } from "./PositionPopup.js";
/** @beta */
export class InputEditorCommitHandler {
    constructor(onCommit) {
        this.onCommit = onCommit;
        this.handleCommit = (args) => {
            let newValue = 0;
            if (args.newValue.valueFormat === PropertyValueFormat.Primitive &&
                args.newValue.value !== undefined) {
                newValue = args.newValue.value;
            }
            this.onCommit(newValue);
        };
    }
}
/** Popup component for Input Editor
 * @alpha
 */
export class InputEditorPopup extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {
            size: { width: -1, height: -1 },
        };
        this._onSizeKnown = (newSize) => {
            if (newSize.height === this.state.size.height &&
                newSize.width === this.state.size.width)
                return;
            this.setState({ size: newSize });
        };
    }
    render() {
        const point = PopupManager.getPopupPosition(this.props.el, this.props.pt, this.props.offset, this.state.size);
        return (React.createElement(PositionPopup, { key: this.props.id, point: point, onSizeKnown: this._onSizeKnown },
            React.createElement(DivWithOutsideClick, { onOutsideClick: this.props.onCancel },
                React.createElement(PositionPopupContent, null,
                    React.createElement(EditorContainer, { propertyRecord: this.props.record, onCommit: this.props.commitHandler.handleCommit, onCancel: this.props.onCancel, setFocus: true })))));
    }
}
//# sourceMappingURL=InputEditorPopup.js.map