<template>
  <div class="leader-ansys">
    <div class="content">
      <img :src="title" class="title-img" style="margin-top: -22px; margin-left: -24px" />

      <div class="charts-wrapper">
        <div v-for="chart in anlysisList" :key="chart.id" class="chart-section">
          <div class="section-title">
            <span class="icon"></span>
            <span>{{ chart.title }}</span>
          </div>

          <div class="chart-layout">
            <div class="y-axis-labels">
              <span v-for="(row, index) in chart.rows" :key="index">{{ row.label }}</span>
            </div>

            <div class="chart-main">
              <div class="grid-lines">
                <div v-for="n in chart.xAxis.length" :key="n" class="line"></div>
              </div>
              <div class="bars">
                <div v-for="(row, index) in chart.rows" :key="index" class="bar-container">
                  <div
                    class="bar"
                    :class="row.type"
                    :style="{ width: (row.value / chart.max) * 100 + '%' }"
                  ></div>
                  <span class="value" :class="{ highlight: row.highlight }">{{ row.value }}</span>
                </div>
              </div>
              <div class="x-axis-labels">
                <span v-for="n in chart.xAxis" :key="n">{{ n }}</span>
                <span class="unit">{{ chart.unit }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps } from "vue";
const props = defineProps({
  anlysisList: {
    type: Array,
    default: []
  },
  title: {
    type: String,
    default: ""
  }
});
</script>

<style scoped lang="less">
.leader-ansys {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  backdrop-filter: blur(4px);
  color: #fff;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  box-sizing: border-box;

  .content {
    position: relative;
    z-index: 1;
    padding: 15px 25px;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    .title-img {
      display: block;
      margin: 0 auto;
    }
    .charts-wrapper {
      margin-top: 24px;
      display: flex;
      flex-direction: column;
      gap: 20px;

      .section-title {
        display: flex;
        align-items: center;
        margin-bottom: 16px;
        font-size: 16px;
        color: #e0e0e0;

        .icon {
          width: 8px;
          height: 8px;
          background-color: #3aa1f8;
          margin-right: 8px;
          flex-shrink: 0;
        }
      }

      .chart-layout {
        display: flex;

        .y-axis-labels {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          padding-right: 15px;
          font-size: 14px;
          color: #a9c2e1;
          text-align: right;
          height: 70px;
          flex-shrink: 0;
        }

        .chart-main {
          flex: 1;
          position: relative;

          .grid-lines {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 70px; /* Match Y-axis height */
            display: flex;
            justify-content: space-between;
            .line {
              width: 1px;
              height: 100%;
              border-left: 1px dotted rgba(58, 90, 142, 0.5);
            }
          }

          .bars {
            position: relative;
            z-index: 2;
            height: 70px;
            display: flex;
            flex-direction: column;
            justify-content: space-around;

            .bar-container {
              display: flex;
              align-items: center;

              .bar {
                height: 10px;
                border-radius: 5px;
                transition: width 0.5s ease-out;
              }

              .value {
                margin-left: 8px;
                font-size: 14px;
                color: #ffffff;
                white-space: nowrap;
                font-size: 20px;
              }
            }
          }

          .x-axis-labels {
            margin-top: 8px;
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: rgba(169, 194, 225, 0.7);
            position: relative;
            .unit {
              position: absolute;
              right: -25px;
              top: 0;
            }
          }
        }
      }
    }
  }

  .bar.leader {
    background: linear-gradient(90deg, #2e7cfb 0%, #3adbf3 100%);
  }

  .bar.user {
    background: linear-gradient(90deg, #07bdb8 0%, #3adbf3 100%);
  }

  .value.highlight {
    background-color: #d65050;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 12px;
  }
}
</style>
