<script lang="ts">
  const {
    text,
    label = '查看说明',
  }: {
    text: string;
    label?: string;
  } = $props();
</script>

<button
  type="button"
  class="tf-info-tooltip nopan nodrag"
  aria-label={label}
  data-help={text}
>
  <svg viewBox="0 0 24 24" aria-hidden="true">
    <circle cx="12" cy="12" r="9" />
    <path d="M12 10.75V16" />
    <circle cx="12" cy="7.75" r="0.75" class="tf-info-tooltip-dot" />
  </svg>
</button>

<style lang="less">
  .tf-info-tooltip {
    position: relative;
    display: inline-flex;
    flex: 0 0 16px;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    color: var(--tf-text-secondary);
    cursor: help;
    background: transparent;
    border: 0;
    border-radius: 50%;

    svg {
      width: 15px;
      height: 15px;
      overflow: visible;
      fill: none;
      stroke: currentcolor;
      stroke-width: 1.8;
      stroke-linecap: round;
    }

    .tf-info-tooltip-dot {
      fill: currentcolor;
      stroke: none;
    }

    &:hover,
    &:focus {
      color: var(--tf-primary-color);
      background: var(--tf-primary-soft-bg);
      outline: none;
    }

    &:focus {
      box-shadow: 0 0 0 2px var(--tf-primary-soft-border);
    }

    &::after {
      position: absolute;
      bottom: calc(100% + 8px);
      left: 0;
      z-index: 120;
      width: 280px;
      max-width: calc(100vw - 32px);
      padding: 10px 12px;
      font-size: 12px;
      font-weight: 400;
      line-height: 1.5;
      color: var(--tf-tip-text);
      text-align: left;
      white-space: normal;
      pointer-events: none;
      visibility: hidden;
      content: attr(data-help);
      background: var(--tf-tip-bg);
      border-radius: 8px;
      box-shadow: var(--tf-shadow-medium);
      opacity: 0;
    }

    &:hover::after,
    &:focus::after {
      visibility: visible;
      opacity: 1;
    }
  }
</style>
