/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Item
 */
import { Orientation } from "@itwin/core-react";
import { ItemDefBase } from "./ItemDefBase";
/** Abstract base class that is used by classes to execute an action when pressed.
 * @public
 */
class ActionButtonItemDef extends ItemDefBase {
    constructor(itemProps, onItemExecuted) {
        super(itemProps);
        /** Called when the size of the action button is initialized and the size is known */
        this.handleSizeKnown = (size) => {
            this.size = size;
        };
        this.execute = this.execute.bind(this);
        this._onItemExecuted = onItemExecuted;
    }
    /** Called when the action button is invoked by a click or touch */
    execute() {
        if (this._commandHandler && this._commandHandler.execute) {
            if (this._commandHandler.getCommandArgs)
                this._commandHandler.execute(this._commandHandler.getCommandArgs());
            else
                this._commandHandler.execute(this._commandHandler.parameters);
        }
        // istanbul ignore else
        if (this._onItemExecuted)
            this._onItemExecuted(this);
    }
    /** Determines the dimension in a given orientation */
    getDimension(orientation) {
        let dimension = ActionButtonItemDef.defaultButtonSize;
        if (this.size)
            dimension =
                orientation === Orientation.Horizontal
                    ? this.size.width
                    : this.size.height;
        return dimension;
    }
}
/** The default button size for all action buttons */
ActionButtonItemDef.defaultButtonSize = 42;
export { ActionButtonItemDef };
//# sourceMappingURL=ActionButtonItemDef.js.map