@charset 'utf-8';

/*  ========================================================================
    JUICE -> ELEMENTS -> FORM -> CUSTOM -> FILE
    ========================================================================  */

// Check if the elements with custom file should be imported
@if $import-elements and $import-element-custom-file {
    .custom-file {
        align-items: center;
        display: flex;
        height: $custom-file-height;
        margin-bottom: $custom-file-element-spacing;

        // Nested selectors
        input[type=file] {
            clip: rect(0, 0, 0, 0);
            height: 0;
            opacity: 0;
            padding: 0;
            position: absolute;
            margin: 0;
            width: 0;

            // Pseudo classes
            &:focus + div {
                box-shadow: 0 0 0 $custom-file-accessibility-focus-width $custom-file-accessibility-focus-color;
            }
        }

        .custom-file__button,
        .custom-file__text {
            border-left-width: 0;
            border-right-width: 0;
            height: 100%;

            // Pseudo classes
            &:first-of-type {
                border-left-width: $custom-file-border-width-left;
                border-bottom-left-radius: $custom-file-border-radius-bottom-left;
                border-top-left-radius: $custom-file-border-radius-top-left;

                // Pseudo classes
                &:not(.custom-file__text) {
                    border-right-width: $custom-file-border-width-divider;
                }
            }

            &:last-of-type {
                border-bottom-right-radius: $custom-file-border-radius-bottom-right;
                border-right-width: $custom-file-border-width-right;
                border-top-right-radius: $custom-file-border-radius-top-right;

                // Pseudo classes
                &:not(.custom-file__text) {
                    border-left-width: $custom-file-border-width-divider;
                }
            }
        }

        .custom-file__button {
            @extend #{$button};
            border-radius: 0;
            margin: 0;
        }

        .custom-file__text {
            @include truncate-text;
            align-items: center;
            background-color: $custom-file-background-color;
            border: 0 $custom-file-border-style $custom-file-border-color;
            border-bottom-width: $custom-file-border-width-bottom;
            border-top-width: $custom-file-border-width-top;
            color: $custom-file-font-color;
            display: flex;
            flex-grow: 1;
            font-family: $custom-file-font-family;
            font-size: $custom-file-font-size;
            padding: 0 $custom-file-content-spacing;
        }

        // Check if the custom file size modifiers should be declared
        @if $custom-file-size-modifiers {
            // Cycle through all of the sizes
            @each $size in $sizes {
                // Modifiers: Sizes
                &.is-#{$size} {
                    height: map-get($custom-file-height-sizes, $size);

                    // Nested selectors
                    .custom-file__text {
                        padding: 0 map-get($custom-file-content-spacing-sizes, $size);
                    }
                }

                // Check if the custom file size modifiers with breakpoints should be declared
                @if $custom-file-size-modifiers-with-breakpoints {
                    // Cycle through all of the breakpoints
                    @each $breakpoint-name, $breakpoint-value in $breakpoints {
                        // Breakpoint
                        @include breakpoint($breakpoint-name) {
                            // Modifiers: Size
                            &.is-#{$size}\@#{$breakpoint-name} {
                                height: map-get($custom-file-height-sizes, $size);

                                // Nested selectors
                                .custom-file__text {
                                    padding: 0 map-get($custom-file-content-spacing-sizes, $size);
                                }
                            }
                        }
                    }
                }
            }
        }

        // Check if the custom file feedback modifiers should be declared
        @if $custom-file-feedback-modifiers {
            // Cycle through all of the feedback colors
            @each $feedback-name, $feedback-value in $feedback-colors {
                // Modifiers: Feedback colors
                &.has-#{$feedback-name} {
                    // Nested selectors
                    .custom-file__button {
                        @extend .button.has-#{$feedback-name};
                        content: ''; // Stops incorrect editor syntax highlighting
                    }

                    .custom-file__text {
                        border-color: feedback-color($feedback-name);
                    }
                }
            }
        }
    }
}
