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

const FIXED_SAFE_DAYS = 165

const safeDays = ref(FIXED_SAFE_DAYS)

async function loadSafeDays() {
  try {
    await IotStatApi.getSafeCount()
  } 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 h-9">
      <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: 22px 24px 18px;
  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: 32px;
  width: 320px;
  height: 320px;
}

.safe-day-panel__orbit--inner {
  top: 62px;
  width: 240px;
  height: 240px;
  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: 5px 12px;
  font-family: YouSheBiaoTiHei, sans-serif;
  font-size: 16px;
  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: 14px;
  margin-top: auto;
  margin-bottom: auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.safe-day-panel__headline {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 1px;
  color: #24364f;
}

.safe-day-panel__value-row {
  display: flex;
  margin-top: 10px;
  align-items: flex-end;
  justify-content: center;
}

.safe-day-panel__value {
  font-family: YouSheBiaoTiHei, sans-serif;
  font-size: 82px;
  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: 10px;
  font-family: YouSheBiaoTiHei, sans-serif;
  font-size: 30px;
  line-height: 1;
  color: #f08c2e;
}

.safe-day-panel__subline {
  margin-top: 10px;
  font-size: 15px;
  color: #6f85aa;
}
</style>
