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

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

export default {
    name: 'ScrollAreaContent',
    extends: BaseScrollAreaContent,
    inheritAttrs: false,
    inject: ['$pcScrollArea'],
    computed: {
        contentStyle() {
            const scrollMeta = this.$pcScrollArea?.scrollMeta;

            return {
                minWidth: scrollMeta && !scrollMeta.hiddenX ? 'fit-content' : undefined,
                minHeight: scrollMeta && !scrollMeta.hiddenY ? 'fit-content' : undefined
            };
        },
        attrs() {
            return mergeProps(this.a11yAttrs, this.ptmi('root'));
        },
        a11yAttrs() {
            return {
                style: this.contentStyle
            };
        }
    }
};
</script>
