<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 { isElement } from '@primeuix/utils/dom';
import { mergeProps } from 'vue';
import BaseGalleryContent from './BaseGalleryContent.vue';

export default {
    name: 'GalleryContent',
    extends: BaseGalleryContent,
    inheritAttrs: false,
    inject: ['$pcGallery'],
    beforeUnmount() {
        this.$pcGallery?.setContentEl(null);
    },
    methods: {
        setRef(el) {
            const dom = isElement(el) ? el : (el?.$el ?? null);

            this.$pcGallery?.setContentEl(dom);
        }
    },
    computed: {
        attrs() {
            return mergeProps(this.a11yAttrs, this.ptmi('root'));
        },
        a11yAttrs() {
            return {
                ref: this.setRef,
                'data-pc-name': 'gallerycontent',
                'data-pc-section': 'root'
            };
        }
    }
};
</script>
