import { __esDecorate, __runInitializers } from "tslib";
import { html, nothing } from 'lit';
import { property, queryAsync, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { when } from 'lit/directives/when.js';
import { ripple } from '../../effects/rippleDirective.js';
import { isDisabled, setDisabled } from '../../../lib/disabled.js';
import { UiElement } from '../../UiElement.js';
import { Easing } from '../../motion/animation.js';
import '../../ripple/ui-ripple.js';
let UiTab = (() => {
    let _classSuper = UiElement;
    let _instanceExtraInitializers = [];
    let _set_disabled_decorators;
    let _selected_decorators;
    let _selected_initializers = [];
    let _selected_extraInitializers = [];
    let _priority_decorators;
    let _priority_initializers = [];
    let _priority_extraInitializers = [];
    let _indicated_decorators;
    let _indicated_initializers = [];
    let _indicated_extraInitializers = [];
    let _hasIcon_decorators;
    let _hasIcon_initializers = [];
    let _hasIcon_extraInitializers = [];
    let _showRipple_decorators;
    let _showRipple_initializers = [];
    let _showRipple_extraInitializers = [];
    let _ripple_decorators;
    let _ripple_initializers = [];
    let _ripple_extraInitializers = [];
    return class UiTab extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _set_disabled_decorators = [property({ reflect: true, type: Boolean })];
            _selected_decorators = [property({ reflect: true, type: Boolean })];
            _priority_decorators = [property({ reflect: true, type: Boolean })];
            _indicated_decorators = [property({ reflect: true, type: Boolean })];
            _hasIcon_decorators = [state()];
            _showRipple_decorators = [state()];
            _ripple_decorators = [queryAsync('ui-ripple')];
            __esDecorate(this, null, _set_disabled_decorators, { kind: "setter", name: "disabled", static: false, private: false, access: { has: obj => "disabled" in obj, set: (obj, value) => { obj.disabled = value; } }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _selected_decorators, { kind: "accessor", name: "selected", static: false, private: false, access: { has: obj => "selected" in obj, get: obj => obj.selected, set: (obj, value) => { obj.selected = value; } }, metadata: _metadata }, _selected_initializers, _selected_extraInitializers);
            __esDecorate(this, null, _priority_decorators, { kind: "accessor", name: "priority", static: false, private: false, access: { has: obj => "priority" in obj, get: obj => obj.priority, set: (obj, value) => { obj.priority = value; } }, metadata: _metadata }, _priority_initializers, _priority_extraInitializers);
            __esDecorate(this, null, _indicated_decorators, { kind: "accessor", name: "indicated", static: false, private: false, access: { has: obj => "indicated" in obj, get: obj => obj.indicated, set: (obj, value) => { obj.indicated = value; } }, metadata: _metadata }, _indicated_initializers, _indicated_extraInitializers);
            __esDecorate(this, null, _hasIcon_decorators, { kind: "accessor", name: "hasIcon", static: false, private: false, access: { has: obj => "hasIcon" in obj, get: obj => obj.hasIcon, set: (obj, value) => { obj.hasIcon = value; } }, metadata: _metadata }, _hasIcon_initializers, _hasIcon_extraInitializers);
            __esDecorate(this, null, _showRipple_decorators, { kind: "accessor", name: "showRipple", static: false, private: false, access: { has: obj => "showRipple" in obj, get: obj => obj.showRipple, set: (obj, value) => { obj.showRipple = value; } }, metadata: _metadata }, _showRipple_initializers, _showRipple_extraInitializers);
            __esDecorate(this, null, _ripple_decorators, { kind: "accessor", name: "ripple", static: false, private: false, access: { has: obj => "ripple" in obj, get: obj => obj.ripple, set: (obj, value) => { obj.ripple = value; } }, metadata: _metadata }, _ripple_initializers, _ripple_extraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        get disabled() {
            return isDisabled(this);
        }
        /**
         * When set, the button is a disabled state.
         * @attribute
         */
        set disabled(value) {
            const old = isDisabled(this);
            setDisabled(this, value);
            this.requestUpdate('disabled', old);
        }
        #selected_accessor_storage = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _selected_initializers, false
        /**
         * @attribute
         */
        ));
        /**
         * Whether the tab is selected. Note, this does not correspond to the `selected` state
         * in the `ui-tabs`. This is only to render the tab in the selected state.
         * @attribute
         */
        get selected() { return this.#selected_accessor_storage; }
        set selected(value) { this.#selected_accessor_storage = value; }
        #priority_accessor_storage = (__runInitializers(this, _selected_extraInitializers), __runInitializers(this, _priority_initializers, 'primary'
        /**
         * @attribute
         */
        ));
        /**
         * @attribute
         */
        get priority() { return this.#priority_accessor_storage; }
        set priority(value) { this.#priority_accessor_storage = value; }
        #indicated_accessor_storage = (__runInitializers(this, _priority_extraInitializers), __runInitializers(this, _indicated_initializers, false));
        /**
         * @attribute
         */
        get indicated() { return this.#indicated_accessor_storage; }
        set indicated(value) { this.#indicated_accessor_storage = value; }
        #hasIcon_accessor_storage = (__runInitializers(this, _indicated_extraInitializers), __runInitializers(this, _hasIcon_initializers, false));
        get hasIcon() { return this.#hasIcon_accessor_storage; }
        set hasIcon(value) { this.#hasIcon_accessor_storage = value; }
        #showRipple_accessor_storage = (__runInitializers(this, _hasIcon_extraInitializers), __runInitializers(this, _showRipple_initializers, false));
        get showRipple() { return this.#showRipple_accessor_storage; }
        set showRipple(value) { this.#showRipple_accessor_storage = value; }
        #ripple_accessor_storage = (__runInitializers(this, _showRipple_extraInitializers), __runInitializers(this, _ripple_initializers, void 0));
        get ripple() { return this.#ripple_accessor_storage; }
        set ripple(value) { this.#ripple_accessor_storage = value; }
        getRipple = (__runInitializers(this, _ripple_extraInitializers), () => {
            this.showRipple = true;
            return this.ripple;
        });
        constructor() {
            super();
            this.actionController.cancelKeyboardEvents = true;
            this.addEventListener('keydown', this.handleKeyDown.bind(this));
            this.addEventListener('keyup', this.handleKeyUp.bind(this));
            this.addEventListener('click', this.handleClick.bind(this));
            this.addEventListener('pointerdown', this.handlePointerDown.bind(this));
            this.addEventListener('pointerup', this.handlePointerUp.bind(this));
            this.addEventListener('pointercancel', this.handlePointerCancel.bind(this));
            this.addEventListener('pointerleave', this.handlePointerLeave.bind(this));
            this.addEventListener('contextmenu', this.handleContextMenu.bind(this));
        }
        connectedCallback() {
            super.connectedCallback();
            if (!this.hasAttribute('role')) {
                this.setAttribute('role', 'tab');
            }
            if (!this.hasAttribute('aria-selected')) {
                this.setAttribute('aria-selected', 'false');
            }
        }
        endPress(config) {
            super.endPress(config);
            const { cancelled, reason } = config;
            if (cancelled) {
                return;
            }
            if (reason === 'enter' || reason === 'space') {
                this.click();
            }
        }
        /**
         * Sets the `_hasIcon` state property when the "icon" slot change event is dispatched.
         */
        handleIconChange(e) {
            const slot = e.target;
            this.hasIcon = !!slot.assignedNodes().length;
        }
        /**
         * When `indicated` is `true` it animates the indicator to highlight the position of the tab.
         */
        highlight() {
            if (!this.indicated) {
                return;
            }
            const pointer = this.shadowRoot?.querySelector('.pointer');
            if (!pointer) {
                return;
            }
            const frames = [
                {
                    width: `40px`,
                },
                {
                    width: `80px`,
                },
                {
                    width: `40px`,
                },
            ];
            pointer.animate(frames, {
                duration: 360,
                iterations: 1,
                easing: Easing.STANDARD,
            });
        }
        render() {
            const { pressed = false } = this;
            const containerClasses = classMap({
                surface: true,
                withIcon: this.hasIcon,
                pressed,
            });
            return html `
      <div class="${containerClasses}" ${ripple(this.getRipple)}>
        <div class="container"></div>
        ${when(this.showRipple, this.renderRipple)}
        <div class="content">
          ${this.renderIcon()}
          <div class="tab-content"><slot></slot></div>
        </div>
        ${this.renderIndicator()}
      </div>
    `;
        }
        renderIcon() {
            return html `
      <div class="icon">
        <slot name="icon" @slotchange="${this.handleIconChange}"></slot>
      </div>
    `;
        }
        renderRipple = () => {
            const { disabled } = this;
            return html `<ui-ripple class="ripple" ?disabled="${disabled}"></ui-ripple>`;
        };
        renderIndicator() {
            const { indicated, priority } = this;
            if (!indicated) {
                return nothing;
            }
            const classes = {
                indicator: true,
                primary: priority === 'primary',
            };
            return html `<div class="${classMap(classes)}">
      <span role="presentation" class="pointer"></span>
    </div>`;
        }
    };
})();
export default UiTab;
//# sourceMappingURL=Tab.js.map