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

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

export default {
    name: 'CarouselContent',
    extends: BaseCarouselContent,
    inheritAttrs: false,
    inject: ['$pcCarousel'],
    methods: {
        setContentElRef(el) {
            this.$pcCarousel?.setContentEl(el?.$el ?? el);
        }
    },
    computed: {
        attrs() {
            return mergeProps(this.a11yAttrs, this.ptmi('root'));
        },
        a11yAttrs() {
            return {
                ref: this.setContentElRef,
                'data-pc-name': 'carouselcontent',
                'data-pc-section': 'root',
                style: this.sx('root'),
                'data-orientation': this.$pcCarousel?.orientation,
                'data-align': this.$pcCarousel?.align,
                'data-page': this.$pcCarousel?.d_page,
                'data-swiping': this.$pcCarousel?.swiping ? '' : undefined,
                'data-autosize': this.$pcCarousel?.autoSize ? '' : undefined,
                'aria-live': this.$pcCarousel?.isAutoplay?.() ? 'off' : 'polite',
                onPointerdown: this.$pcCarousel?.onContentPointerDown,
                onPointermove: this.$pcCarousel?.onContentPointerMove,
                onPointerup: this.$pcCarousel?.onContentPointerUp,
                onWheel: this.$pcCarousel?.onContentWheel
            };
        }
    }
};
</script>
