<template>
  <div class="border-container">
    <div class="border-glow"></div>
    <div class="border-inner p-[2px]">
        <slot></slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: "BackgroundColor",
    data() {
      return {
        animationFrame: null,
      };
    },
    mounted() {
      this.startAnimation();
    },
    beforeUnmount() {
      if (this.animationFrame) {
        cancelAnimationFrame(this.animationFrame);
      }
    },
    methods: {
      startAnimation() {
        const borderGlow = document.querySelector(".border-glow");
        let angle = 0;

        const animate = () => {
          angle = (angle + 1) % 360;
          if (borderGlow) {
            borderGlow.style.background = `conic-gradient(
            from ${angle}deg,
            hsla(0, 0%, 0%, 0.25),
            hsla(214, 60%, 34%, 0.2),
            hsla(220, 74%, 35%, 0.1),
            hsla(219, 100%, 58%, 0.1),
            hsla(219, 100%, 58%, 0.2),
            hsla(219, 100%, 58%, 0.5),
            hsla(219, 100%, 58%, 0)
          )`;
          }
          this.animationFrame = requestAnimationFrame(animate);
        };

        animate();
      },
    },
  };
</script>

<style scoped>
  .border-container {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
  }

  .border-glow {
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    width: auto;
    height: auto;
    background: conic-gradient(
      from 0deg,
      hsla(0, 0%, 0%, 0.25),
      hsla(214, 60%, 34%, 0.2),
      hsla(220, 74%, 35%, 0.1),
      hsla(219, 100%, 58%, 0.1),
      hsla(219, 100%, 58%, 0.2),
      hsla(219, 100%, 58%, 0.5),
      hsla(219, 100%, 58%, 0)
    );
    border-radius: inherit;
    filter: blur(2px);
    pointer-events: none;
    mix-blend-mode: plus-lighter;
    z-index: 0;
  }

  .border-inner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border: 0.5px solid hsla(236, 100%, 66%, 0.48);
    border-radius: inherit;
    pointer-events: none;
    box-sizing: border-box;
  }

  /* 内容区域样式 */
  .border-container > :not(.border-glow):not(.border-inner) {
    position: relative;
    z-index: 1;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
  }
</style>
