@use "sass:list";
@use "../../../bulma/sass/utilities" as bulma-utilities;
@use "../../../bulma/sass/form/file" as bulma-file;

.upload {
    position: relative;
    display: inline-flex;

    input[type="file"] {
        position: absolute;
        top: 0;
        left: 0;
        z-index: -1;
        width: 100%;
        height: 100%;
        cursor: pointer;
        outline: none;
        opacity: 0;
    }

    .upload-draggable {
        padding: 0.25em;
        cursor: pointer;
        border: 1px dashed var(--grey-light);
        border-radius: var(--radius-large);

        &.is-disabled {
            cursor: not-allowed;
            opacity: 0.5;
        }

        &.is-loading {
            position: relative;
            pointer-events: none;
            opacity: 0.5;

            &::after {
                @extend %loader;

                top: 0;
                left: calc(50% - 1.5em);
                width: 3em;
                height: 3em;
                border-width: 0.25em;
            }
        }

        &:hover,
        &.is-hovered {
            @each $name, $pair in bulma-file.$file-colors {
                $color: list.nth($pair, 1);
                &.is-#{$name} {
                    background: var(--#{$name}-light);
                    border-color: var(--#{$name});
                }
            }
        }

        &.is-expanded {
            width: 100%;
        }
    }

    &.is-expanded {
        width: 100%;
    }

    &.is-rounded {
        border-radius: var(--radius-rounded);

        .file-name {
            border-top-right-radius: var(--radius-rounded);
            border-bottom-right-radius: var(--radius-rounded);
        }
    }
}

// temporary IE 11 hack !!!
@include bulma-utilities.ie11 {
    .upload {
        input[type="file"] {
            z-index: auto;
        }

        .upload-draggable + input[type="file"] {
            z-index: -1;
        }
    }
}
