<template>
  <div class="banner m-auto relative sm:flex">
    <div class="md:w-screen-xl m-auto py-10">
        <div class="gap-8 sm:gap-y-16 lg:items-center" v-if="form">
          <div class="w-full sm:px-0 px-4">
            <div class="flex flex-1">
              <template v-if="form.websiteLogo">
                <el-image :src="form.websiteLogo" shape="square"
                           class="hidden-sm-and-down bg-white w-[128px] h-[128px] cursor-pointer rounded-avatar shadow-sm hover:shadow mr-6"/>
              </template>
              <div class="title flex flex-col">
                <h1
                    class="text-2xl font-bold tracking-tight text-gray-900 dark:text-white sm:text-3xl lg:text-3xl">
                  <el-space>
                    <span>{{ form.websiteName }}</span>
                  </el-space>
                </h1>
                <div class="my-1 text-sm text-gray-500 w-auto sm:max-w-3xl max-w-xs flex-1 dark:text-gray-400">
                  {{ form?.comments || desc }}
                </div>
                <el-space class="btn">
                  <nuxt-link target="_blank"><el-button type="primary" round>获取</el-button></nuxt-link>
                </el-space>
              </div>
            </div>
          </div>
        </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type {ApiResult} from "~/api";
import type {Company} from "~/api/system/company/model";
import type {CmsWebsite} from "~/api/cms/cmsWebsite/model";

const token = useToken();

const props = withDefaults(
    defineProps<{
      title?: string;
      desc?: string;
      buyUrl?: string;
      form?: CmsWebsite;
      value?: number;
    }>(),
    {}
);

const emit = defineEmits<{
  (e: 'done'): void
}>()

const onBuy = (item: Company) => {
  // if(item.type === 1){
  //   // 插件
  //   openSpmUrl(`/product/checkout`,item,item.productId)
  // }else {
  //   // 产品
  //   openSpmUrl(`/product/create`,item,item.productId)
  // }
  if (!token.value || token.value == '') {
    ElMessage.error('请先登录');
    setTimeout(() => {
      navigateTo(`/product/create`)
    }, 500)

  }
}

// 安装插件
const installPlug = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '安装中...'
  })
  useClientRequest<ApiResult<any>>(`/system/menu/install`, {
    method: 'POST',
    body: {
      companyId: getIdBySpm(5)
    }
  }).then(res => {
    if (res.code === 0) {
      setTimeout(() => {
        ElMessage.success(res.message);
        loading.close()
        emit('done')
      }, 500)
    }
  })
}

</script>
<style scoped lang="less">
.rounded-avatar {
  border-radius: 30px;
}

.rounded-avatar-xs {
  border-radius: 20px;
}
</style>
