import {ref} from "vue"

const visible = ref(false)
const mediaData = ref(null)
const previewType = ref("image")

export function useMediaPreview() {
  const showPreview = (content, type = "image") => {
    console.log("显示媒体预览:", content, type)
    mediaData.value = content
    previewType.value = type
    visible.value = true
  }

  const hidePreview = () => {
    visible.value = false
    mediaData.value = null
    previewType.value = "image"
  }

  return {
    visible,
    mediaData,
    previewType,
    showPreview,
    hidePreview,
  }
}

// 导出一个函数供组件直接使用
export default function previewMedia(content, type = "image") {
  const {showPreview} = useMediaPreview()
  showPreview(content, type)
}
