"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.InputEditorPopup = exports.InputEditorCommitHandler = void 0;
const React = require("react");
const appui_abstract_1 = require("@itwin/appui-abstract");
const components_react_1 = require("@itwin/components-react");
const core_react_1 = require("@itwin/core-react");
const PopupManager_1 = require("./PopupManager");
const PositionPopup_1 = require("./PositionPopup");
/** @beta */
class InputEditorCommitHandler {
    constructor(onCommit) {
        this.onCommit = onCommit;
        this.handleCommit = (args) => {
            let newValue = 0;
            // istanbul ignore else
            if (args.newValue.valueFormat === appui_abstract_1.PropertyValueFormat.Primitive && args.newValue.value !== undefined) {
                newValue = args.newValue.value;
            }
            this.onCommit(newValue);
        };
    }
}
exports.InputEditorCommitHandler = InputEditorCommitHandler;
/** Popup component for Input Editor
 * @alpha
 */
class InputEditorPopup 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) });
        };
    }
    /** @internal */
    render() {
        const point = PopupManager_1.PopupManager.getPopupPosition(this.props.el, this.props.pt, this.props.offset, this.state.size);
        return (React.createElement(PositionPopup_1.PositionPopup, { key: this.props.id, point: point, onSizeKnown: this._onSizeKnown },
            React.createElement(core_react_1.DivWithOutsideClick, { onOutsideClick: this.props.onCancel },
                React.createElement(PositionPopup_1.PositionPopupContent, null,
                    React.createElement(components_react_1.EditorContainer, { propertyRecord: this.props.record, onCommit: this.props.commitHandler.handleCommit, onCancel: this.props.onCancel, setFocus: true })))));
    }
}
exports.InputEditorPopup = InputEditorPopup;
//# sourceMappingURL=InputEditorPopup.js.map