var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { consume } from '@lit/context';
import { LitElement, html } from 'lit';
import { property } from 'lit/decorators.js';
import { EaseInOut } from '../../animations/easings.js';
import { addAnimationController } from '../../animations/player.js';
import { carouselContext } from '../common/context.js';
import { registerComponent } from '../common/definitions/register.js';
import { createCounter, formatString } from '../common/util.js';
import { animations } from './animations.js';
import { styles } from './themes/carousel-slide.base.css.js';
class IgcCarouselSlideComponent extends LitElement {
    static register() {
        registerComponent(IgcCarouselSlideComponent);
    }
    get _index() {
        return this._carousel ? this._carousel.slides.indexOf(this) : 0;
    }
    get _total() {
        return this._carousel ? this._carousel.slides.length : 0;
    }
    get _animation() {
        const animation = this._carousel?.animationType ?? 'slide';
        if (animation === 'slide') {
            return this._carousel?.vertical ? 'slideVer' : 'slideHor';
        }
        return animation;
    }
    get _labelFormat() {
        return this._carousel ? this._carousel.slidesLabelFormat : '';
    }
    async toggleAnimation(type, direction = 'normal') {
        const animation = animations.get(this._animation).get(type);
        const options = {
            duration: 320,
            easing: EaseInOut.Quad,
            direction,
        };
        const [_, event] = await Promise.all([
            this._animationPlayer.stopAll(),
            this._animationPlayer.play(animation(options)),
        ]);
        return event.type === 'finish';
    }
    constructor() {
        super();
        this._animationPlayer = addAnimationController(this);
        this.active = false;
        this.previous = false;
        this._internals = this.attachInternals();
        this._internals.role = 'tabpanel';
        this._internals.ariaRoleDescription = 'slide';
    }
    willUpdate() {
        this._internals.ariaLabel = formatString(this._labelFormat, this._index + 1, this._total);
    }
    connectedCallback() {
        super.connectedCallback();
        this.id =
            this.id || `igc-carousel-slide-${IgcCarouselSlideComponent.increment()}`;
    }
    render() {
        return html ` <slot></slot> `;
    }
}
IgcCarouselSlideComponent.styles = styles;
IgcCarouselSlideComponent.tagName = 'igc-carousel-slide';
IgcCarouselSlideComponent.increment = createCounter();
export default IgcCarouselSlideComponent;
__decorate([
    consume({ context: carouselContext, subscribe: true })
], IgcCarouselSlideComponent.prototype, "_carousel", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], IgcCarouselSlideComponent.prototype, "active", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], IgcCarouselSlideComponent.prototype, "previous", void 0);
//# sourceMappingURL=carousel-slide.js.map