/* @settings

name: Adwaita
id: com-github-birneee-obsidian-adwaita
settings:
    -
        title: Window Buttons
        description: Style of minimize, maximize and close window buttons
        type: heading
        level: 2
        collapsed: false
    -
        id: adwaita-mod
        title: Enable
        description: Whether to use the Adwaita style window buttons
        type: class-select
        default: adwaita-mod-linux-only
        allowEmpty: false
        options:
            -
                label: Always
                value: adwaita-mod-always
            -
                label: Linux Only
                value: adwaita-mod-linux-only
            -
                label: Never
                value: adwaita-mod-never
    -
        id: adwaita-mod-scale
        title: Scale
        description:
        type: variable-number
        default: 1
    -
        id: adwaita-mod-right-margin
        title: Right Margin
        type: variable-number
        default: 8
        format: px
    -
        id: adwaita-window-button-minimize-hide
        title: Hide minimize button
        type: class-toggle
    -
        id: adwaita-window-button-maximize-hide
        title: Hide maximize button
        type: class-toggle
    -
        id: adwaita-window-button-close-hide
        title: Hide close button
        type: class-toggle

    -
        title: Tabs
        type: heading
        level: 2
        collapsed: false
    -
        id: adwaita-tabs
        title: Enable
        description: Whether to use the Adwaita style tabs
        type: class-select
        default: adwaita-tabs-linux-only
        allowEmpty: false
        options:
            -
                label: Always
                value: adwaita-tabs-always
            -
                label: Linux Only
                value: adwaita-tabs-linux-only
            -
                label: Never
                value: adwaita-tabs-never
    -
        id: adwaita-tabs-short
        title: Short
        type: class-toggle

    -
        title: Colors
        type: heading
        level: 2
        collapsed: false
    -
        id: adwaita-colors
        title: Enable
        description: Whether to use the Adwaita colors
        type: class-select
        default: adwaita-colors-linux-only
        allowEmpty: false
        options:
            -
                label: Always
                value: adwaita-colors-always
            -
                label: Linux Only
                value: adwaita-colors-linux-only
            -
                label: Never
                value: adwaita-colors-never

    -
        title: Font
        type: heading
        level: 2
        collapsed: false
    -
        id: adwaita-font
        title: Enable
        description: Whether to use the Cantarell font (must be installed on system)
        type: class-select
        default: adwaita-font-linux-only
        allowEmpty: false
        options:
            -
                label: Always
                value: adwaita-font-always
            -
                label: Linux Only
                value: adwaita-font-linux-only
            -
                label: Never
                value: adwaita-font-never

    -
        title: Icons
        type: heading
        level: 2
        collapsed: false
    -
        id: adwaita-icon
        title: Enable
        description: Whether to use the Adwaita icons
        type: class-select
        default: adwaita-icons-linux-only
        allowEmpty: false
        options:
            -
                label: Always
                value: adwaita-icons-always
            -
                label: Linux Only
                value: adwaita-icons-linux-only
            -
                label: Never
                value: adwaita-icons-never
*/

:root {
    --adwaita-mod-scale: 1;
    --adwaita-mod-right-margin: 8px;
    /* TODO window radius */
}

@import '../generated/adw_icons';
@import 'adwaita_colors_dark';
@import 'adwaita_colors_light';
@import 'adwaita_colors';

body {
    @include adwaita-colors;
    &.theme-dark {
        @include adwaita-colors-dark;
    }
    &.theme-light {
        @include adwaita-colors-light;
    }
}

// Adwaita colors
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux, // default if obsidian-style-settings plugin is not used
body.adwaita-colors-always,
body.adwaita-colors-linux-only.mod-linux {
    --titlebar-background: var(--adwaita-headerbar-backdrop-color);
    --titlebar-background-focused: var(--adwaita-headerbar-bg-color);
    --titlebar-text-color-focused: var(--adwaita-headerbar-fg-color);
    --text-normal: var(--adwaita-view-fg-color);
    &.is-focused {
        .workspace-tabs.mod-top .workspace-tab-header-container,
        .sidebar-toggle-button {
            --icon-color: var(--adwaita-headerbar-fg-color);
            --icon-color-hover: var(--adwaita-headerbar-fg-color);
            --icon-color-focused: var(--adwaita-headerbar-fg-color);
            --tab-text-color-focused: var(--adwaita-headerbar-fg-color);
            --tab-text-color-focused-active-current: var(--adwaita-headerbar-fg-color);
        };
    }
    &.theme-dark  {
        --titlebar-text-color: #919191;
        --icon-color: #929292;
        --icon-color-hover: #929292;
        --icon-color-focused: #929292;
        --tab-text-color: #929292;
        --tab-text-color-focused: #8a8a8a;
        --tab-text-color-focused-active-current: #8a8a8a;
        --background-modifier-hover: #323232;
        &.is-focused {
            .workspace-tabs.mod-top .workspace-tab-header-container,
            .sidebar-toggle-button {
                --background-modifier-hover: #464646;
            };
        }
    }
    &.theme-light {
        --titlebar-text-color: #8c8c8c;
        --icon-color: #939393;
        --icon-color-hover: #939393;
        --icon-color-focused: #939393;
        --tab-text-color: #939393;
        --tab-text-color-focused: #939393;
        --tab-text-color-focused-active-current: #939393;
        --background-modifier-hover: #f0f0f0;
        &.is-focused {
            .workspace-tabs.mod-top .workspace-tab-header-container,
            .sidebar-toggle-button {
                --background-modifier-hover: #d8d8d8;
            };
        }
    }
    .titlebar-button.mod-logo:hover {
        background-color: inherit;
    }
}

// Adwaita window mod buttons
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux, // default if obsidian-style-settings plugin is not used
body.adwaita-mod-always,
body.adwaita-mod-linux-only.mod-linux {
    --frame-right-space: calc(var(--adwaita-mod-scale) * 120px);
    --adwaita-mod-foreground-focus: var(--adwaita-headerbar-fg-color);

    &.theme-dark {
        --adwaita-mod-background: #2e2e2e;
        --adwaita-mod-background-focus: #444444;
        --adwaita-mod-background-hover: #4f4f4f;
        --adwaita-mod-background-active: #6e6e6e;
        --adwaita-mod-foreground: #929292;
    }
    
    &.theme-light {
        --adwaita-mod-background: #efefef;
        --adwaita-mod-background-focus: #d8d8d8;
        --adwaita-mod-background-hover: #cfcfcf;
        --adwaita-mod-background-active: #b3b3b3;
        --adwaita-mod-foreground: #949494;
    }

    &.adwaita-window-button-minimize-hide .titlebar-button-container.mod-right .titlebar-button.mod-minimize{
        display: none
    }

    &.adwaita-window-button-maximize-hide .titlebar-button-container.mod-right .titlebar-button.mod-maximize{
        display: none
    }

    &.adwaita-window-button-close-hide .titlebar-button-container.mod-right .titlebar-button.mod-close{
        display: none
    }



    &.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide),
    &.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide),
    &.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide){
        --frame-right-space: calc(var(--adwaita-mod-scale) * (120px - 38px));
    }

    &.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide),
    &.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide),
    &.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide){
        --frame-right-space: calc(var(--adwaita-mod-scale) * (120px - 38px - 38px));
    }

    &.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide{
        --frame-right-space: calc(var(--adwaita-mod-scale) * (120px - 38px - 38px - 38px));
    }


    .titlebar-button-container.mod-right {
        transform: scale(var(--adwaita-mod-scale));
        margin-right: var(--adwaita-mod-right-margin);
        transform-origin: right;
    
        .titlebar-button {
            height: 24px;
            width: 24px;
            border-radius: 12px;
            padding: 0;
            margin: auto 0 auto 14px;

            background: var(--adwaita-mod-background);
            color: var(--adwaita-mod-foreground);
    
            &.mod-minimize,
            &.mod-maximize,
            &.mod-close {
                svg {
                    display: none;
                }
            }
    
            &::after {
                content: '';
                background-color: currentColor;
                width: 16px;
                height: 16px;
                margin: auto;
            }
    
            &.mod-minimize::after {
                -webkit-mask-image: var(--adwaita-icon-window-minimize-symbolic);
                mask-image: var(--adwaita-icon-window-minimize-symbolic);
            }
    
            &.mod-maximize::after {
                -webkit-mask-image: var(--adwaita-icon-window-maximize-symbolic);
                mask-image: var(--adwaita-icon-window-maximize-symbolic);
            }
    
            &.mod-close::after {
                -webkit-mask-image: var(--adwaita-icon-window-close-symbolic);
                mask-image: var(--adwaita-icon-window-close-symbolic);
            }
    
            &:hover {
                background: var(--adwaita-mod-background)!important;
            }
    
            svg {
                width: 12px;
                height: 12px;
                margin: auto;
            }
        }
    }
    &.is-focused {
        .titlebar-button-container.mod-right .titlebar-button,
        .modal-close-button {
            background: var(--adwaita-mod-background-focus);
            color: var(--adwaita-mod-foreground-focus);
        
            &:hover {
                background: var(--adwaita-mod-background-hover)!important;
            }
        
            &:active {
                background: var(--adwaita-mod-background-active)!important;
            }
        }
    }

    .modal-close-button {
        height: 24px;
        width: 24px;
        border-radius: 12px;
        color: var(--adwaita-mod-foreground);
        background: var(--adwaita-mod-background);
        transform: scale(var(--adwaita-mod-scale));
        transform-origin: right;
    
        &:before {
            content: '';
            display: block;
            width: 16px;
            height: 16px;
            margin: auto;
            top: 50%;
            position: absolute;
            transform: translateY(-50%);
            -webkit-mask-image: var(--adwaita-icon-window-close-symbolic);
            mask-image: var(--adwaita-icon-window-close-symbolic);
            background-color: currentColor;
        }
    }
}


// Adwaita tabs
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux, // default if obsidian-style-settings plugin is not used
body.adwaita-tabs-always,
body.adwaita-tabs-linux-only.mod-linux {
    --tab-radius-active: 6px;

    &:not(.adwaita-tabs-short) {
        --tab-width: 10000px; /* infinite width */
        --tab-max-width: none;
    }

    &.theme-dark {
        --tab-background-active: #323232;
        &.is-focused {
            --tab-background-active: #464646;
        }
    }

    &.theme-light {
        --tab-background-active: #f0f0f0;
        &.is-focused {
            --tab-background-active: #d8d8d8;
        }
    }

    .workspace-tab-header-container {
        .workspace-tab-header-container-inner {
            --tab-outline-width: 0;
        }
        .workspace-tab-header-new-tab {
            margin-right: var(--size-4-1);
        }
    }

    .workspace-tab-header-new-tab {
        order: 1;
    }

    .workspace-tab-header-tab-list,
    .sidebar-toggle-button.mod-right {
        order: 2
    }

    .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header {
        padding: 0;
        margin: 5px 3px 5px 2px;

        &.is-active {
            color: var(--tab-text-color-focused);
        }
        &:before,
        &:after {
            content: none;
        }
        .workspace-tab-header-inner::after {
            right: -6px;
        }
        .workspace-tab-header-inner-title {
            padding-left: 20px;
            text-align: center;
        }
        &:last-child {
            .workspace-tab-header-inner::after {
                content: none;
            }
        }
        .workspace-tab-header-inner-close-button {
            opacity: 0;
            display: flex;
        }
        &.is-active, :hover {
            .workspace-tab-header-inner-close-button {
                opacity: 1;
            }
        }
    }
}

// Adwaita font
body:not(.adwaita-font-always, .adwaita-font-linux-only, .adwaita-font-never).mod-linux, // default if obsidian-style-settings plugin is not used
body.adwaita-font-always,
body.adwaita-font-linux-only.mod-linux {    
    --titlebar-height: 45px;
    --font-interface-theme: Cantarell;
    --font-ui-small: 15px;
    --h1-weight: 900;
    .titlebar-text {
        top: 10px;
        height: auto;
    }
}

// Adwaita icons
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux, // default if obsidian-style-settings plugin is not used
body.adwaita-icons-always,
body.adwaita-icons-linux-only.mod-linux {
    --titlebar-height: 45px;
    --header-height: 46px;

    svg.logo-wireframe {
        stroke-width: 45;
    }

    &.is-frameless:not(.is-hidden-frameless) {
        .app-container {
            margin-top: -9px;
            height: calc(100% + 9px);
        }
    }

    @mixin replace-svg($icon-url) {
        svg {
            display: none;
        }
        &::after {
            content: '';
            background-color: currentColor!important;
            -webkit-mask-image: $icon-url;
            mask-image: $icon-url;
            width: 16px;
            height: 16px;
            margin: auto;
        }
    }

    .sidebar-toggle-button,
    .workspace-tab-header-new-tab,
    .workspace-tab-header-tab-list,
    .mod-left-split .workspace-tabs .workspace-tab-header-container-inner,
    .mod-right-split .workspace-tabs .workspace-tab-header-container-inner {
        margin-top: 0;
        padding-top: 0;
        padding-bottom: 0;
    }

    .mod-left-split .workspace-tabs .workspace-tab-header,
    .mod-right-split .workspace-tabs .workspace-tab-header,
    .sidebar-toggle-button .clickable-icon,
    .workspace-tabs.mod-top .workspace-tab-header-container .clickable-icon {
        height: 34px;
        min-width: 34px;
        margin-top: auto;
        margin-bottom: auto;
    }

    .sidebar-toggle-button.mod-left .clickable-icon {
        @include replace-svg(var(--adwaita-icon-sidebar-show-symbolic))
    }

    .sidebar-toggle-button.mod-right .clickable-icon {
        @include replace-svg(var(--adwaita-icon-sidebar-show-right-symbolic))
    }

    .workspace-tab-header-new-tab .clickable-icon {
        @include replace-svg(var(--adwaita-icon-tab-new-symbolic))
    }

    .workspace-tab-header-tab-list .clickable-icon {
        @include replace-svg(var(--adwaita-icon-go-down-symbolic))
    }

    .workspace-tab-header-inner-close-button {
        @include replace-svg(var(--adwaita-icon-window-close-symbolic))
    }

    .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon {
        @include replace-svg(var(--adwaita-icon-folder-visiting-symbolic))
    }

    .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon {
        @include replace-svg(var(--adwaita-icon-folder-saved-search-symbolic))
    }
}
