@use '../../styles/variables';

.thy-loading {
    display: block;
    width: 100%;

    &:not(.thy-loading-mask):not(.thy-loading-done) {
        display: flex;
        align-items: center;
        justify-content: center;
        padding-top: 20px;
        padding-bottom: 20px;
    }

    &.thy-loading-simple:not(.thy-loading-mask):not(.thy-loading-done) {
        display: inline-flex;
        width: auto;
        padding-top: 0;
        padding-bottom: 0;
        vertical-align: middle;
    }

    &.thy-loading-mask {
        position: relative;

        > .thy-loading-indicator {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 1;
            display: flex;
            background: rgba(0, 0, 0, 0.2);
        }

        > .thy-loading-container {
            display: flow-root;
        }
    }

    // 绝对定位的指示器不参与宽度计算。简单模式改为同一格子叠放，
    // 宽度取内容和指示器的较大值，文案才能把宿主撑开，遮罩仍盖住内容。
    &.thy-loading-simple.thy-loading-mask {
        display: inline-grid;
        width: auto;
        max-width: 100%;
        vertical-align: middle;

        > .thy-loading-indicator,
        > .thy-loading-container {
            grid-area: 1 / 1;
        }

        > .thy-loading-indicator {
            position: relative;
            inset: auto;
            white-space: nowrap;
        }
    }

    &.thy-loading-done {
        display: contents;
    }
}

.thy-loading-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: normal;
    color: inherit;
}

.thy-loading-tips {
    line-height: variables.$line-height-base;
}

.thy-loading-container {
    display: contents;
}

.thy-loading-ellipsis {
    position: relative;
    display: inline-block;
    flex: none;
    width: 33px;
    height: 8px;

    &:before,
    &:after {
        content: '';
        display: block;
        position: absolute;
        top: 0;
        height: 8px;
        width: 8px;
        border-radius: 4px;
    }

    &:before {
        animation: loading-ellipsis-b 1s ease-in-out infinite;
        background: variables.$primary;
        opacity: 0.4;
    }

    &:after {
        animation: loading-ellipsis-a 1s ease-in-out infinite;
        background: variables.$primary;
        opacity: 0.8;
    }

    .thy-spot {
        position: absolute;
        top: 0;
        left: 13px;
        height: 8px;
        width: 8px;
        background: variables.$primary;
        border-radius: 4px;
    }
}

@keyframes loading-ellipsis-b {
    0% {
        left: 0;
        transform: scale(1.1);
    }
    50% {
        left: 25px;
        transform: scale(1);
    }
    100% {
        left: 0;
        transform: scale(1.1);
    }
}

@keyframes loading-ellipsis-a {
    0% {
        left: 25px;
        transform: scale(1.1);
    }
    50% {
        left: 0;
        transform: scale(1);
    }
    100% {
        left: 25px;
        transform: scale(1.1);
    }
}
