<template>
  <div>
    <div class="item">
      <div class="item-top">
        <img v-if="data.RelAvatarLink" class="avatar" :src="data.RelAvatarLink" />
        <img v-else class="avatar" :avatar="data.OwnerName" />
        <div class="content">
          <div class="title">
            <div class="title-l">
              <a :href="`/${data.OwnerName}/${data.Name}`" :title="`${data.OwnerName}/${data.Name}`">
                <span class="title-1">{{ data.OwnerName }}</span>
                <span class="title-1"> / </span>
                <span class="title-2" v-html="data.NameShow"></span>
              </a>
            </div>
            <span class="title-r">
              <span class="t-item" :title="$t('repos.watch')">
                <i class="ri-eye-line"></i>
                <span>{{ data.NumWatches }}</span>
              </span>
              <span class="t-item" :title="$t('repos.star')">
                <i class="ri-star-line"></i>
                <span>{{ data.NumStars }}</span>
              </span>
              <span class="t-item" :title="$t('repos.fork')">
                <svg class="svg octicon-repo-forked" width="12" height="12" aria-hidden="true">
                  <use xlink:href="#octicon-repo-forked"></use>
                </svg>
                <span>{{ data.NumForks }}</span></span>
            </span>
          </div>
          <div class="descr" v-html="data.DescriptionShow"></div>
          <div class="tags" v-if="data.Topics">
            <a v-for="(item, index) in data.TopicsShow" :key="index" class="tag"
              :class="(item.topic.toLocaleLowerCase() == topic.toLocaleLowerCase() ? 'tag-focus' : '')"
              :href="`/explore/repos?q=&topic=${item.topic}&sort=hot`" v-html="item.topicShow"></a>
          </div>
          <div class="repo-datas">
            <span class="repo-datas-item" v-show="(data.DatasetCnt > 0)">
              <i class="ri-stack-line"></i>
              <span class="label">{{ $t('repos.dataset') }}：</span>
              <span class="value">{{ data.DatasetCnt }}</span>
            </span>
            <span class="repo-datas-item" v-show="(data.ModelCnt > 0)">
              <i class="ri-send-plane-2-line"></i>
              <span class="label">{{ $t('repos.model') }}：</span>
              <span class="value">{{ data.ModelCnt }}</span>
            </span>
            <span class="repo-datas-item" v-show="(data.AiTaskCnt > 0)">
              <i class="ri-order-play-line"></i>
              <span class="label">{{ $t('repos.aiTask') }}：</span>
              <span class="value">{{ data.AiTaskCnt }}</span>
            </span>
          </div>
        </div>
      </div>
      <div class="item-bottom">
        <div>
          <span>{{ $t('repos.updated') }}</span>
          <el-tooltip effect="dark" :content="dateFormat(data.UpdatedUnix)" placement="top-start">
            <span>{{ calcFromNow(data.UpdatedUnix) }}</span>
          </el-tooltip>
          <span style="margin-left:8px;" v-if="data.PrimaryLanguage"><i class="color-icon"
              :style="{ backgroundColor: data.PrimaryLanguage.Color }"></i>{{ data.PrimaryLanguage.Language }}</span>
        </div>
        <div class="contributors">
          <span class="contributors-count">{{ $t('repos.contributors') }}&nbsp;</span>
          <span> 17+ </span>
          <span class="contributors-avatar">
            <img class="avatar" src="/user/avatar/Itx003/-1">
            <img class="avatar" src="/user/avatar/Itx003/-1">
            <img class="avatar" src="/user/avatar/Itx003/-1">
            <img class="avatar" src="/user/avatar/Itx003/-1">
            <img class="avatar" src="/user/avatar/Itx003/-1">
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import relativeTime from 'dayjs/plugin/relativeTime';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import 'dayjs/locale/zh-cn';
import 'dayjs/locale/en';
import dayjs from 'dayjs';
import { lang } from '~/langs';

dayjs.locale(lang == 'zh-CN' ? 'zh-cn' : 'en');
dayjs.extend(relativeTime);
dayjs.extend(localizedFormat);

export default {
  name: "ReposItem",
  props: {
    data: { type: Object, default: () => ({}) },
    topic: { type: String, default: '' }
  },
  components: {},
  data() {
    return {
      contributors: [],
    };
  },
  methods: {
    calcFromNow(unix) {
      return dayjs(unix * 1000).fromNow();
    },
    dateFormat(unix) {
      return lang == 'zh-CN' ? dayjs(unix * 1000).format('YYYY年MM月DD日 HH时mm分ss秒') :
        dayjs(unix * 1000).format('ddd, D MMM YYYY HH:mm:ss [CST]');
    }
  },
  mounted() { },
};
</script>

<style scoped lang="less">
.item {
  width: 100%;
  border-color: rgba(157, 197, 226, 0.4);
  border-width: 1px;
  border-style: solid;
  box-shadow: rgb(157 197 226 / 20%) 0px 5px 10px 0px;
  border-radius: 15px;
  font-size: 14px;
  padding: 20px 26px 10px 26px;
  margin-bottom: 40px;
}

.item-top {
  display: flex;
}

.item-top .avatar {
  width: 38px;
  height: 38px;
  margin-right: 10px;
}

.content {
  flex: 1;
  overflow: hidden;
}

.content .title {
  display: flex;
  align-items: center;
  height: 30px;
  margin: 4px 0 8px;
}

.content .title-l {
  flex: 1;
  overflow: hidden;
  width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content .title-1 {
  font-size: 18px;
  color: rgba(16, 16, 16, 0.6);
}

.content .title-2 {
  font-size: 18px;
  color: rgba(16, 16, 16, 1);
  font-weight: bold;
}

.content .title-r {
  width: 240px;
  display: flex;
  align-items: center;
  font-size: 12px;
  font-weight: bold;
  color: rgb(26, 40, 51, 0.9);
  justify-content: flex-end;
}

.content .t-item {
  margin-left: 12px;
  display: flex;
  align-items: center;
}

.content .t-item i {
  margin-right: 4px;
}

.content .descr {
  font-size: 14px;
  color: rgba(16, 16, 16, 0.8);
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  max-height: 120px;
  white-space: break-spaces;
}

.content .tags {
  margin-bottom: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content .tag {
  color: rgba(16, 16, 16, 0.8);
  border-radius: 4px;
  font-size: 14px;
  background: rgba(232, 232, 232, 0.6);
  padding: 2px 6px;
  margin-right: 8px;

  &.tag-focus {
    color: red;
  }
}

.content .repo-datas {
  display: flex;
  align-items: center;
  margin: 24px 0;
}

.content .repo-datas-item {
  display: flex;
  align-items: center;
  margin-right: 24px;
}

.content .repo-datas-item i {
  color: rgba(2, 107, 251, 0.54);
  margin-right: 4px;
  font-size: 16px;
}

.content .repo-datas-item .label {
  color: rgba(2, 107, 251, 0.54);
  margin-right: 4px;
}

.content .repo-datas-item .value {
  font-weight: bold;
}

.item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(157, 197, 226, 0.2);
  padding-top: 10px;
  font-size: 12px;
  color: rgba(16, 16, 16, 0.6);
}

.item-bottom .contributors {
  display: flex;
  align-items: center;
}

.item-bottom .contributors-avatar {
  display: flex;
  align-items: center;
  margin-left: 16px;
}

.item-bottom .avatar {
  width: 25px;
  height: 25px;
  margin-left: -6px;
  border-radius: 100%;
  border: 1px solid white;
}
</style>
