<script lang="ts">
import { type HTMLAttributes, computed } from 'vue'
import type { PolymorphicProps } from '../factory.ts'

export interface TreeViewBranchContentBaseProps extends PolymorphicProps {}
export interface TreeViewBranchContentProps
  extends
    TreeViewBranchContentBaseProps,
    /**
     * @vue-ignore
     */
    HTMLAttributes {}

interface VisibilityProps {
  hidden?: boolean
  'data-state'?: string
}
</script>

<script setup lang="ts">
import { useForwardExpose } from '../../utils/use-forward-expose.ts'
import { Collapsible } from '../collapsible/index.ts'
import { useTreeViewContext } from './use-tree-view-context.ts'
import { useTreeViewNodePropsContext } from './use-tree-view-node-props-context.ts'
import { createSplitProps } from '../create-split-props.ts'

const splitVisibilityProps = createSplitProps<VisibilityProps>()

defineProps<TreeViewBranchContentProps>()
const treeView = useTreeViewContext()
const ndoeProps = useTreeViewNodePropsContext()

const branchContentProps = computed(() => {
  const contentProps = treeView.value.getBranchContentProps(ndoeProps)
  const [, ownProps] = splitVisibilityProps(contentProps as VisibilityProps, ['hidden', 'data-state'])
  return ownProps
})

useForwardExpose()
</script>

<template>
  <Collapsible.Content v-bind="branchContentProps" :as-child="asChild">
    <slot />
  </Collapsible.Content>
</template>
