<script lang="ts" setup>
import CountTo from '@/components/count-to1.vue'
import { IotStatApi } from '@/api/pms/stat'

const FIXED_SAFE_DAYS = 123

const safeDays = ref(FIXED_SAFE_DAYS)

async function loadSafeDays() {
  try {
    const res = await IotStatApi.getSafeCount1(158)
    safeDays.value = res
  } catch (error) {
    console.error('获取安全生产天数失败:', error)
  } finally {
    // safeDays.value = FIXED_SAFE_DAYS
  }
}

onMounted(() => {
  loadSafeDays()
})
</script>

<template>
  <div class="panel flex flex-col">
    <div class="panel-title">
      <div class="icon-decorator">
        <span></span>
        <span></span>
      </div>
      安全生产天数
    </div>

    <div class="safe-day-panel flex-1 min-h-0">
      <div class="safe-day-panel__orbit safe-day-panel__orbit--outer"></div>

      <div class="safe-day-panel__top">
        <span class="safe-day-panel__tag">SAFE RUN</span>
      </div>

      <div class="safe-day-panel__center">
        <div class="safe-day-panel__headline">连续安全生产</div>
        <div class="safe-day-panel__value-row translate-x-1.5">
          <CountTo
            class="safe-day-panel__value"
            :start-val="0"
            :end-val="safeDays"
            :duration="1200" />
          <span class="safe-day-panel__unit">天</span>
        </div>
        <!-- <div class="safe-day-panel__subline">截至当前未发生安全生产事故</div> -->
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import url('@/styles/kb.scss');

.safe-day-panel {
  position: relative;
  display: flex;
  padding: calc(22px * var(--kb-scale, 1)) calc(24px * var(--kb-scale, 1))
    calc(18px * var(--kb-scale, 1));
  overflow: hidden;
  flex-direction: column;
}

.safe-day-panel__orbit {
  position: absolute;
  left: 50%;
  border: 1px solid rgb(31 91 184 / 15%);
  border-radius: 999px;
  transform: translateX(-50%);
}

.safe-day-panel__orbit--outer {
  top: calc(32px * var(--kb-scale, 1));
  width: calc(320px * var(--kb-scale, 1));
  height: calc(320px * var(--kb-scale, 1));
}

.safe-day-panel__orbit--inner {
  top: calc(62px * var(--kb-scale, 1));
  width: calc(240px * var(--kb-scale, 1));
  height: calc(240px * var(--kb-scale, 1));
  border-style: dashed;
}

.safe-day-panel__top,
.safe-day-panel__center {
  position: relative;
  z-index: 1;
}

.safe-day-panel__top {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.safe-day-panel__tag {
  padding: calc(5px * var(--kb-scale, 1)) calc(12px * var(--kb-scale, 1));
  font-family: YouSheBiaoTiHei, sans-serif;
  font-size: calc(16px * var(--kb-scale, 1));
  line-height: 1;
  letter-spacing: 1px;
  color: #1f5bb8;
  background: rgb(255 255 255 / 72%);
  border: 1px solid rgb(255 255 255 / 75%);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 85%);
}

.safe-day-panel__center {
  display: flex;
  padding-top: calc(14px * var(--kb-scale, 1));
  margin-top: auto;
  margin-bottom: auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.safe-day-panel__headline {
  font-size: calc(20px * var(--kb-scale, 1));
  font-weight: 600;
  letter-spacing: 1px;
  color: #24364f;
}

.safe-day-panel__value-row {
  display: flex;
  margin-top: calc(10px * var(--kb-scale, 1));
  align-items: flex-end;
  justify-content: center;
}

.safe-day-panel__value {
  font-family: YouSheBiaoTiHei, sans-serif;
  font-size: calc(82px * var(--kb-scale, 1));
  line-height: 0.9;
  letter-spacing: 2px;
  color: #1f5bb8;
  text-shadow: 0 12px 24px rgb(31 91 184 / 12%);
}

.safe-day-panel__unit {
  padding-bottom: calc(10px * var(--kb-scale, 1));
  font-family: YouSheBiaoTiHei, sans-serif;
  font-size: calc(30px * var(--kb-scale, 1));
  line-height: 1;
  color: #f08c2e;
}

.safe-day-panel__subline {
  margin-top: calc(10px * var(--kb-scale, 1));
  font-size: calc(15px * var(--kb-scale, 1));
  color: #6f85aa;
}
</style>
