/* eslint-disable @typescript-eslint/no-unused-vars */
/**
 * @license
 * Copyright 2022 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { __esDecorate, __runInitializers } from "tslib";
import { LitElement } from 'lit';
import { state } from 'lit/decorators.js';
import { ActionController, } from '../controllers/ActionController.js';
/**
 * The base class for all API Client's base UI elements.
 * Only contains logic to be applied to **all** UI elements.
 *
 * @fires action - An event dispatched when the UI element was activated (pointer, keyboard).
 */
let UiElement = (() => {
    let _classSuper = LitElement;
    let _pressed_decorators;
    let _pressed_initializers = [];
    let _pressed_extraInitializers = [];
    return class UiElement extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _pressed_decorators = [state()];
            __esDecorate(this, null, _pressed_decorators, { kind: "accessor", name: "pressed", static: false, private: false, access: { has: obj => "pressed" in obj, get: obj => obj.pressed, set: (obj, value) => { obj.pressed = value; } }, metadata: _metadata }, _pressed_initializers, _pressed_extraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        actionController = new ActionController(this);
        #pressed_accessor_storage = __runInitializers(this, _pressed_initializers, void 0);
        /**
         * Indicates the component is in the pressed state.
         */
        get pressed() { return this.#pressed_accessor_storage; }
        set pressed(value) { this.#pressed_accessor_storage = value; }
        /**
         * Hook method called when we've confirmed that the gesture is intended to be
         * a press. Subclasses should change the visual state of the control to
         * 'active' at this point, and possibly fire an event. Subclasses should
         * override this method if more needs to be done.
         *
         * @param options `positionEvent` is the Event that is considered the
         * beginning of the press. Null if this was a keyboard interaction.
         */
        beginPress(options) {
            this.pressed = true;
        }
        /**
         * Hook method called when the control goes from a pressed to unpressed
         * state.
         *
         * @param options If `cancelled` is true, means the user canceled the action.
         *    Subclasses which trigger events on endPress() should check the value
         *    of this flag, and modify their behavior accordingly.
         */
        endPress({ cancelled, actionData }) {
            this.pressed = false;
            if (!cancelled) {
                this.dispatchEvent(new CustomEvent('action', {
                    detail: actionData,
                    bubbles: true,
                    composed: true,
                }));
            }
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@pointerdown="${this.handlePointerDown}"`
         */
        handlePointerDown(e) {
            this.actionController.pointerDown(e);
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@pointerup="${this.handlePointerUp}"`
         */
        handlePointerUp(e) {
            this.actionController.pointerUp(e);
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@pointercancel="${this.handlePointerCancel}"`
         */
        handlePointerCancel(e) {
            this.actionController.pointerCancel(e);
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@pointerleave="${this.handlePointerleave}"`
         */
        handlePointerLeave(e) {
            this.actionController.pointerLeave(e);
        }
        /**
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@pointerenter="${this.handlePointerEnter}"`
         */
        handlePointerEnter(e) {
            // this.actionController.pointerEnter(e)
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@click="${this.handleClick}"`
         */
        handleClick(e) {
            this.actionController.click(e);
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@contextmenu="${this.handleContextMenu}"`
         */
        handleContextMenu() {
            this.actionController.contextMenu();
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@keydown="${this.handleKeyDown}"`
         */
        handleKeyDown(e) {
            this.actionController.keyDown(e);
        }
        /**
         * Hook method for the ActionController.
         * Subclasses should add this method as an event handler on the interactive
         * template element with `@keyup="${this.handleKeyUp}"`
         */
        handleKeyUp(e) {
            this.actionController.keyUp(e);
        }
        /**
         * A common way for an element to notify a change.
         */
        notifyChange() {
            this.dispatchEvent(new Event('change'));
        }
        constructor() {
            super(...arguments);
            __runInitializers(this, _pressed_extraInitializers);
        }
    };
})();
export { UiElement };
//# sourceMappingURL=UiElement.js.map