<template>
    <component v-if="!asChild" :is="as" :class="cx('root')" v-bind="attrs">
        <slot></slot>
    </component>
    <slot v-else :a11yAttrs="a11yAttrs" :class="cx('root')" :disabled="effectiveDisabled"></slot>
</template>

<script>
import { mergeProps } from 'vue';
import BaseCarouselNext from './BaseCarouselNext.vue';

export default {
    name: 'CarouselNext',
    extends: BaseCarouselNext,
    inheritAttrs: false,
    inject: ['$pcCarousel'],
    computed: {
        effectiveDisabled() {
            return this.disabled || !!this.$pcCarousel?.isNextDisabled;
        },
        attrs() {
            return mergeProps(this.asAttrs, this.a11yAttrs, this.ptmi('root'));
        },
        asAttrs() {
            return this.as === 'BUTTON' ? { type: 'button', disabled: this.effectiveDisabled } : undefined;
        },
        a11yAttrs() {
            return {
                'aria-label': this.$pcCarousel?.ariaNextButtonLabel,
                'data-pc-name': 'carouselnext',
                'data-pc-section': 'root',
                disabled: this.effectiveDisabled,
                'data-orientation': this.$pcCarousel?.orientation,
                'data-align': this.$pcCarousel?.align,
                'data-page': this.$pcCarousel?.d_page,
                'data-disabled': this.effectiveDisabled,
                'data-swiping': this.$pcCarousel?.swiping ? '' : undefined,
                onClick: this.$pcCarousel?.next
            };
        }
    }
};
</script>
