<script lang="ts" setup>
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
import { createChannelPublishColumn } from '../columns'
import { INDEX_URLS } from '@/config/base-url'
import useTableScrollY from '@/composables/useTableScrollY'
import { copyToClip } from '@/utils/copy'

const { pageContentWrapRef, tableContentY } = useTableScrollY()

const router = useRouter()

const channelPublishList = reactive([
  {
    type: 'web',
  },
])

const columns = createChannelPublishColumn(handleClickChannelPublishTableAction)

function handleClickChannelPublishTableAction(actionType: string) {
  switch (actionType) {
    case 'accessPage':
      handleAccessPage()
      break
    case 'copyLink':
      handleCopyShareLink()
      break
  }
}

function handleAccessPage() {
  const channleUrl = `${INDEX_URLS[window.ENV || 'DEV']}share/web_source/${router.currentRoute.value.params.agentId}`
  location.href = channleUrl
}

function handleCopyShareLink() {
  const channleUrl = `${INDEX_URLS[window.ENV || 'DEV']}share/web_source/${router.currentRoute.value.params.agentId}`
  copyToClip(channleUrl)
  window.$message.success('链接复制成功，快分享给你的好友吧！')
}
</script>

<template>
  <div ref="pageContentWrapRef" class="h-full overflow-hidden p-5">
    <NDataTable
      :bordered="true"
      :bottom-bordered="true"
      :single-line="false"
      :data="channelPublishList"
      :columns="columns"
      :max-height="tableContentY"
      :scroll-x="1220"
    />
  </div>
</template>
