// https://m3.material.io/components/time-pickers/specs

.sd-time_picker {
    display: flex;
    flex-direction: column;
    background: var(--md-sys-color-surface);
    box-sizing: border-box;
    display: inline-block;
    padding: 24px;
    border-radius: 24px;
    color: var(--md-sys-color-on-surface-variant);
    &-headline {
        font-size: 14px;
        margin-bottom: 20px;
    }

    &-selectors {
        // contains time_selectors and period_selectors
        gap: 12px;
        display: flex;
    }

    &[data-sd-direction='horizontal'] {
        .sd-time_picker-selectors {
            align-items: center;
            flex-direction: column;
            gap: 16px;
        }
    }

    &-time_selectors {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    &-time_selector {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    &-time_selector > input {
        display: inline-block;
        width: 96px;
        height: 80px;
        line-height: 80px;
        text-align: center;
        font-size: 60px;
        background: var(--md-sys-color-surface-container-highest);
        border: solid 2px transparent;
        border-radius: 8px;
        outline: none;

        &:focus {
            background: var(--md-sys-color-primary-container);
            border-color: var(--md-sys-color-on-primary-container);
        }
    }

    &-time_selector_separator {
        display: inline-flex;
        width: 24px;
        text-align: center;
        flex-direction: column;
        & > *:first-child {
            font-size: 60px;
        }
    }

    &-period_selectors {
        display: inline-flex;
        border: 1px solid var(--md-sys-color-outline);
        border-radius: 8px;
        box-sizing: border-box;
        overflow: hidden;
        user-select: none;
    }

    &[data-sd-direction='vertical'] {
        .sd-time_picker-period_selectors {
            width: 52px;
            height: 80px;
            flex-direction: column;
        }
    }

    &[data-sd-direction='horizontal'] {
        .sd-time_picker-period_selectors {
            flex-direction: row;
            width: 96px+24px+96px+16px;
        }
    }

    &-period_selector {
        text-align: center;
        cursor: pointer;
        line-height: 40px;
        overflow: hidden;
        -webkit-tap-highlight-color: transparent; // remove webkit blue tap effect

        & > input {
            all: unset;
        }

        &:has(input:checked) {
            background: var(--md-sys-color-tertiary-container);
        }
    }

    &[data-sd-direction='vertical'] {
        .sd-time_picker-period_selector {
            height: 50%;
        }
        .sd-time_picker-period_selector:first-child {
            border-bottom: 1px solid var(--md-sys-color-outline);
        }
    }

    &[data-sd-direction='horizontal'] {
        .sd-time_picker-period_selector {
            width: 50%;
        }
        .sd-time_picker-period_selector:first-child {
            border-right: 1px solid var(--md-sys-color-outline);
        }
    }

    // footer

    &-footer {
        display: flex;
        align-items: center;
        margin-top: 20px;
    }

    &-buttons {
        margin-left: auto;
    }
}

// the clock
.sd-time_picker {
    .sd-time_picker-clock_left {
        display: flex;
        flex-direction: column;
    }
    &[data-sd-direction='horizontal'] {
        .sd-time_picker-clock_container {
            display: flex;
        }
        .sd-time_picker-clock_right {
            padding-left: 52px;
        }
    }
    &[data-sd-direction='horizontal']:has(.sd-time_picker-clock) {
        .sd-time_picker-headline {
            margin-bottom: 72px-20px;
            // Hour/Minute label takes 20px space
            // howerver this label is not specified in the specs
        }
    }
    &[data-sd-direction='vertical'] {
        .sd-time_picker-clock_right {
            padding-top: 36px;
        }
    }

    // positioning
    &-clock {
        box-sizing: content-box;
        --clock-size: 256px;
        --time-size: 48px;
        width: var(--clock-size);
        height: var(--clock-size);
        border-radius: var(--clock-size);
        overflow: hidden;
        background: var(--md-sys-color-surface-container-highest);
        margin: auto;
        position: relative;
        user-select: none;
        touch-action: none;

        time {
            position: absolute;
            width: var(--time-size);
            height: var(--time-size);
            border-radius: var(--time-size);
            --r: calc((var(--clock-size) - var(--time-size)) / 2);
            --x: calc(var(--r) + (var(--r) * cos(var(--d))));
            --y: calc(var(--r) + (var(--r) * sin(var(--d))));
            left: var(--x);
            top: var(--y);
            display: grid;
            place-items: center;
        }

        @for $i from 1 through 12 {
            time:nth-of-type(#{$i}) {
                --d: calc(calc(#{$i} - 4) * 30deg);
            }
        }

        &_center {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: var(--md-sys-color-primary);
            width: 6px;
            height: 6px;
            border-radius: 50%;
        }

        &_arm {
            position: absolute;
            top: calc(var(--time-size) * 0.85);
            left: calc(50% - 1px);
            width: 2px;
            height: calc((var(--clock-size) - var(--time-size) * 0.85 * 2) / 2);
            transform-origin: bottom;
            background: var(--md-sys-color-primary);
            transform: rotate(var(--degree)); // change `--degree` in js

            &::before {
                top: calc(var(--time-size) - 100%);
                left: calc(50% - var(--time-size) / 2);
                position: absolute;
                content: '';
                width: var(--time-size);
                height: var(--time-size);
                border-radius: var(--time-size);
                background: var(--md-sys-color-primary);
            }
        }
    }

    // actions
    &-clock time {
        &:hover {
            cursor: pointer;
            -webkit-tap-highlight-color: transparent; // remove webkit blue tap effect
        }
    }
}
