<template>
  <div class="content">
    <p class="font-w">使用简介</p>
    <p class="text-i">网页内快速接入客服，让网页拥有客服窗口，请把一下代码复制到网页最底部。</p>
    <el-divider />

    <p class="typetitle">获取代码</p>

    <div class="fenlei">
      <div class="code-content-wrap">
        <textarea id="NormalCodeTextarea1" class="code" rows="22">
<script>
  (function() {
  _s = document.createElement('script');
  _s.src="{{ siteUrl }}/customerServer.js"
  _s.onload = function(){
  var option = {
        "authInit":true,
        openUrl: '{{ siteUrl }}',
        token: '{{ uniqueToken }}',
        isShowTip: true,
        mobileIcon: '{{ floatConfig?.mobileImage || "" }}',
        pcIcon: '{{ floatConfig?.pcImage || "" }}',
        windowStyle:'',
      };
      var canCustomerServer = new initCustomerServer(option);
      canCustomerServer.init();
  }
  document.head.appendChild(_s)
  })();
</script>
        </textarea>

        <div class="other-wrap">
          <a class="btn btn-blue btn-large mr10" href="javascript:void(0);" @click="jiazai">点击体验</a>
          <a class="btn btn-blue btn-large" href="javascript:void(0);" @click="getCopy('NormalCodeTextarea1')"><span>复制代码</span></a>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, defineProps, defineEmits } from 'vue';

// 从父组件接收 uniqueToken ✅
const props = defineProps<{
  tokeninfo?: any;
  siteUrl?: string;
  uniqueToken: string;
  floatConfig?: {  // 新增
    pcImage: string;
    mobileImage: string;
  };
}>();

const emit = defineEmits<{
  (e: 'cgetCopy', id: string): void;
}>();

// 点击体验
function jiazai() {
  const token = props.uniqueToken || '';
  window.open(`${location.origin}/chat/index?token=${token}&noCanClose=1`);
}

// 复制
function getCopy(id: string) {
  emit('cgetCopy', id);
}
</script>

<style>
.a {
  display: none;
  display: block;
  border-radius: 8px;
  overflow: hidden;
}
</style>