<template>
  <div class="task-my-box" v-if="data.show">
    <div class="item-title">
      <div class="title-style">{{ props.title }}</div>
    </div>
    <div v-if="data.list.length > 0" class="menu-task-content">
      <div class="menu-item" v-for="(item, index) in data.list" :key="index">
        <div class="menu-icon"
          ><div class="bg" :style="'background-color:' + item.color + ''"></div>
          <Icon :icon="item.icon" :size="22" :color="item.color" class="icon"
        /></div>
        <div class="menu-title">
          <span class="name">{{ item.name }}</span>
          <span class="num">{{ item.count }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { onMounted, reactive } from 'vue';
  import Icon from '/@/components/Icon/index';
  import { myTaskProperties } from '../config/properties';
  import { DesktopComponent } from '/@/enums/desktop';
  import { DesktopConfig } from '/@/model/mobileDesign/designer';
  import { getMyTaskCount } from '/@/api/desktop';
  import { useI18n } from '/@/hooks/web/useI18n';
  const { t } = useI18n();
  const props = withDefaults(
    defineProps<{
      type: DesktopComponent;
      title: string;
      config: DesktopConfig;
    }>(),
    {
      type: DesktopComponent.DEFAULT,
      title: '',
      config: () => {
        return myTaskProperties;
      },
    },
  );
  const data: {
    show: boolean;
    list: Array<{
      icon: string;
      name: string;
      color: string;
      count: number;
    }>;
  } = reactive({
    show: false,
    list: [
      {
        icon: 'ant-design:container-twotone',
        name: t('待办任务'),
        count: 0,
        color: '#ff0033',
      },
      {
        icon: 'fa:tasks',
        name: t('委托任务'),
        count: 0,
        color: '#ff880e',
      },
      {
        icon: 'fa6-solid:list-check',
        name: t('已办任务'),
        count: 0,
        color: '#6fc86f',
      },
    ],
  });
  onMounted(async () => {
    try {
      let res = await getMyTaskCount();
      data.list = [
        {
          icon: 'ant-design:container-twotone',
          name: t('待办任务'),
          count: res.pendingCount,
          color: '#ff0033',
        },
        {
          icon: 'fa:tasks',
          name: t('委托任务'),
          count: res.delegateCount,
          color: '#ff880e',
        },
        {
          icon: 'fa6-solid:list-check',
          name: t('已办任务'),
          count: res.finishedCount,
          color: '#6fc86f',
        },
      ];
    } catch (error) {}
    data.show = true;
  });
</script>

<style lang="less" scoped>
  .task-my-box {
    padding-top: 40px;

    .item-title {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 40px;
      line-height: 40px;
      color: #666;
      font-size: 14px;
      padding-left: 10px;
      font-weight: 700;

      .title-style {
        margin: 12px 0 0;
        line-height: 18px;
        padding-left: 6px;
        border-left: 6px solid #5e95ff;
      }
    }

    .item {
      width: 100%;
      height: 100%;
    }
  }

  .menu-task-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    width: 100%;
    height: 100%;

    .menu-item {
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0 8px;

      .menu-icon {
        position: relative;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items: center;

        .bg {
          border-radius: 50%;
          opacity: 0.1;
          height: 40px;
          width: 40px;
          position: relative;
        }

        .icon {
          position: absolute;
          top: 0;
          left: 0;
          height: 40px;
          width: 40px;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }

      .menu-title {
        color: #262626;
        font-size: 14px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-left: 8px;

        .num {
          font-size: 22px;
          color: #666;
          line-height: 26px;
          font-weight: 600;
        }

        .name {
          color: #999;
          font-size: 12px;
        }
      }
    }
  }
</style>
