@use 'design-system' as *;

.linkIcon {
    position: relative;

    svg {
        pointer-events: none;
    }
}

.docsHeaderIcon {
    width: 28px;
    height: 28px;
    padding: 0;
    margin-left: $spacing-size-1;
    font-size: var(--text-fs-base);
    opacity: 0;
    line-height: 1.2;
    transition: opacity 0.33s ease-in-out;

    svg {
        --icon-size: 18px;
        --icon-color: var(--color-link);

        position: absolute;
        top: 4px;
        left: 4px;
        bottom: unset;
        margin: 0;
        visibility: visible;
    }

    &:hover,
    &:focus-visible,
    &.active {
        opacity: 1;
    }
}

.exampleIcon {
    color: red;
}

// Half highlight icon if hovering over container heading element
h1,
h2,
h3,
h4,
h5,
h6 {
    &:hover .docsHeaderIcon {
        opacity: 1;
    }
}

.tooltip {
    --tooltip-background: var(--color-fg-primary);

    position: absolute;
    display: block;
    color: var(--color-bg-primary);
    top: -38px;
    left: 50%;
    padding: $spacing-size-1 $spacing-size-4;
    white-space: nowrap;
    font-size: var(--text-fs-sm);
    background-color: var(--tooltip-background);
    border-radius: 6px;
    transform: translate(-50%, $spacing-size-1);
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.165s ease-in,
        transform 0.165s ease-in;
    z-index: 1;

    &::before {
        $pointer-size: 8px;

        content: '';
        position: absolute;
        background-color: var(--tooltip-background);
        width: $pointer-size * 2;
        height: $pointer-size * 2;
        transform: rotate(45deg);
        bottom: -7px;
        left: calc(50% - $pointer-size);
        border-radius: 3px;
        z-index: -1;
    }

    .linkIcon:hover &,
    .linkIcon.active & {
        opacity: 1;
        transform: translate(-50%, 0);
        transition:
            opacity 0.33s ease-in,
            transform 0.33s ease-in;
    }

    .linkIcon.active & {
        animation-name: bounce;
        animation-duration: 0.25s;
    }

    #{$selector-darkmode} & {
        --tooltip-background: var(--color-bg-secondary);

        color: var(--color-fg-primary);
        box-shadow: 0 -4px 16px 0 rgba(0, 0, 0, 0.4);
    }
}

@keyframes bounce {
    0% {
        transform: translate(-50%, 0);
    }
    50% {
        transform: translate(-50%, -$spacing-size-1);
    }
    100% {
        transform: translate(-50%, 0);
    }
}
