<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 justify-between">
                <div>
                  <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="text-sm mt-1 text-gray-500 w-auto sm:max-w-4xl line-clamp-2 max-w-xs  dark:text-gray-400">
                    {{ form?.comments }}
                  </div>
                </div>
                <el-space class="btn">
                  <nuxt-link v-if="form.domain" :to="`https://${form.domain}`" target="_blank"><el-button round type="primary">访问</el-button></nuxt-link>
                  <nuxt-link v-if="form.adminUrl" :to="`https://${form.adminUrl}`" target="_blank"><el-button round>管理</el-button></nuxt-link>
<!--                  <el-dropdown>-->
<!--                    <el-button :icon="MoreFilled" round></el-button>-->
<!--                    <template #dropdown>-->
<!--                      <el-dropdown-menu>-->
<!--                        <el-dropdown-item @click="openUrl(`https://git.websoft.top`)">源码</el-dropdown-item>-->
<!--                        <el-dropdown-item divided><nuxt-link to="/developer">编辑</nuxt-link></el-dropdown-item>-->
<!--                      </el-dropdown-menu>-->
<!--                    </template>-->
<!--                  </el-dropdown>-->
                </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";
import {MoreFilled} from "@element-plus/icons-vue";

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>
