@import (once) "../../include/vars";
@import (once) "../../include/mixins";

@listviewItemSelectedBorder: #84bcea;
@listviewItemSelectedBackground: #cce8ff;
@listviewItemHoverBackground: #e5f3ff;

:root {
    --listview-item-border-radius: 4px;
    --listview-item-width: 220px;
    --listview-background: #ffffff;
    --listview-color: #191919;
    --listview-color-secondary: #919191;
    --listview-item-background-hover: #d4e2ff;
    --listview-item-background-active: #d4e2ff;
    --listview-badge-background: transparent;
    --listview-badge-color: #191919;
}

.dark-side {
    --listview-background: #1e1f22;
    --listview-color: #dbdfe7;
    --listview-color-secondary: #bcbcbc;
    --listview-item-background-hover: #2d2d32;
    --listview-item-background-active: #28282c;
    --listview-badge-background: transparent;
    --listview-badge-color: #dbdfe7;
}

.listview {
    position: relative;
    margin: 0;
    padding: 0;
    background-color: var(--listview-background);
    color: var(--listview-color);
    list-style: none inside;
    display: flex;

    &.view-list, &.view-content {
        flex-flow: column wrap;
    }

    &.view-icons-medium, &.view-icons-large, &.view-icons, &.view-tiles {
        flex-flow: row wrap;
    }

    &.view-icons-medium, &.view-icons-large, &.view-icons {
        &.vertical-layout {
            flex-flow: column wrap;
        }
    }
}

.listview {
    .node {
        display: flex;
        cursor: pointer;
        position: relative;
        font-size: 13px;
        border: 1px solid transparent;
        background-color: inherit;
        overflow: hidden;
        border-radius: var(--listview-item-border-radius);
        //border: 1px dashed red;
        padding: 4px 8px;

        @media (hover: hover) {
            &:hover {
                background-color: var(--listview-item-background-hover);
            }
        }
        
        @media (hover: none) {
            &:active {
                background-color: var(--listview-item-background-hover);
            }
        }
        
        .icon {
            width: 22px;
            height: 22px;
            line-height: 22px;
            font-size: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            object-fit: cover;
            stroke: var(--listview-color);
            
            & > * {
                width: 100%;
                height: 100%;
            }
        }
    }

    ul {
        width: 100%;
        margin: 0;
        padding: 0;
        list-style: none inside;
    }

    .node > :is(.content, .desc, .date) {
        display: none;
    }

    &:not(.selectable) {
        .checkbox {
            display: none!important;
        }
    }

    .caption {
        line-height: 1.2;
        font-size: 12px;
    }

    .node-group > .caption {
        font-size: 14px;
    }
    
    .content {
        order: 100;
    }
    
    .checkbox {
        input:focus {
            box-shadow: none;
        }
    }
}

.listview {
    &.view-list {
        display: flex;
        flex-flow: column wrap;        
        
        .node {
            display: flex;
            flex-flow: row nowrap;
            align-items: center;
            justify-content: flex-start;
            gap: 8px;
            width: var(--listview-item-width);
        }
    }
}

.listview {
    &.view-table {
        display: flex;
        flex-flow: column nowrap;
        
        .node {
            display: flex;
            flex-flow: row nowrap;
            align-items: center;
            justify-content: flex-start;
            gap: 8px;
            
            &:not(:last-child) {
                border-bottom: 1px solid var(--border-color);
            }
        }

        .caption {
            width: 160px;
        }

        .desc {
            width: 50%;
            margin-left: auto;
            border-left: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: flex-start;
            padding-left: 16px;
            color: var(--listview-color-secondary);
        }
        
        .date {
            width: 100px;
            border-left: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            justify-content: center;
        }
    }
}

.listview {
    &.view-content {
        display: flex;
        flex-flow: column nowrap;
        
        .node {
            display: flex;
            flex-flow: row wrap;
            align-items: center;
            justify-content: flex-start;
            gap: 0 8px;
            
            &:not(:last-child) {
                border-bottom: 1px solid var(--border-color);
            }

            .desc {
                width: 50%;
                margin-left: auto;
                border-left: 1px solid var(--border-color);
                display: flex;
                align-items: center;
                justify-content: flex-start;
                padding-left: 16px;
                color: var(--listview-color-secondary);
            }

            .date {
                width: 100px;
                border-left: 1px solid var(--border-color);
                display: flex;
                align-items: center;
                justify-content: center;
            }

            .content {
                display: block!important;
                width: 100%;
                flex-shrink: 0;
                order: 100;
            }
            
            .content:has(*) {
                padding: 8px 0;
            }
        }
    }
}

.listview {
    &.view-tiles {
        display: flex;
        flex-flow: row wrap;
        
        .node {
            width: var(--listview-item-width);
            padding: 4px 8px;
            align-items: center;
            border-radius: 4px;
        }
        
        .icon {
            width: 40px;
            height: 40px;
            line-height: 40px;
            font-size: 34px;
            margin: 0;
        }
        
        .caption {
            font-size: 13px;
            margin-left: 0;
        }

        .date {
            position: absolute;
            top: 2px;
            right: 4px;
            font-size: 10px;
            line-height: 1;
        }
        
        .checkbox {
            position: absolute;
            top: 2px;
            left: 2px;
        }
        
        @media (hover: hover) {
            .node:hover {
                .date {
                    display: flex;
                }
            }
        }
        
        @media (hover: none) {
            .node:active {
                .date {
                    display: flex;
                }
            }
        }
    }
}

.listview {
    &.view-icons, &.view-icons-medium, &.view-icons-large {
        display: flex;
        flex-flow: row wrap;
        justify-content: flex-start;
        align-items: flex-start;
        gap: 6px;
        
        .node {
            width: 92px;
            height: 92px;
            display: flex;
            flex-flow: column nowrap;
            align-items: center;
            justify-content: center;

            .icon {
                width: 32px;
                height: 32px;
                line-height: 32px;
                font-size: 32px;
                margin: 6px 0;
            }

            .checkbox {
                position: absolute;
                top: 2px;
                left: 2px;
            }
            
            .desc {
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 10px;
                text-overflow: ellipsis;
                overflow: hidden;
                white-space: nowrap;
                line-height: 1;
            }
        }
    }

    &.view-icons-medium {
        .node {
            width: 124px;
            height: 124px;
            margin: 1px;

            & > .icon {
                width: 54px;
                height: 54px;
                line-height: 54px;
                font-size: 54px;
            }
        }
    }

    &.view-icons-large {
        .node {
            width: 200px;
            height: 200px;
            margin: 2px;
            padding: 30px;

            & > .icon {
                width: 90px;
                height: 90px;
                line-height: 90px;
                font-size: 90px;
            }
        }
    }
}

.listview {
    .node {
        &.current-select {
            background-color: var(--listview-item-background-active);
            border-color: var(--border-color)!important;
        }
    }

    .node-group {
        display: block;
        width: 100%;
        position: relative;
        line-height: 24px;
        flex-shrink: 0;
        cursor: pointer;
        user-select: none;

        .node-toggle {
            position: absolute;
            left: 0;
            top: 0;
            .square(24, px);
            fill: var(--listview-color);
            display: flex;
            align-items: center;
            justify-content: center;
            transition: transform .2s ease-in-out;
        }

        &.expanded {
            & > .node-toggle {
                transform-origin: center;
                .rotate(90deg);
            }
        }
    }

    .node-group + .node-group {
        margin-top: 1rem;
    }

    .node-group > .listview {
        margin-top: .5rem;
    }
    
    li:has(.node-toggle) > .caption{
        margin-left: 24px;
        margin-top: 3px;
    }
}
