@import '../../../styles/fills';
@import '../../../styles/definitions/placeholders';
@import '../../../styles/definitions/breakpoints';
@import '../../../styles/definitions/colors';
@import '../../../styles/definitions/mixins';

//Local Variables
$namespace: ".productListingCard";
$container-selector: "#{$namespace}_container";
$header-selector: "#{$namespace}_header";
$container-grid-view-selector: "#{$container-selector}--grid-view";
$container-list-view-selector: "#{$container-selector}--list-view";
$container-align-left-selector: "#{$container-selector}--left";
$container-align-center-selector: "#{$container-selector}--center";
$container-align-right-selector: "#{$container-selector}--right";

$product-listing-card-container-bgcolor: $white;
$product-listing-card-container-border-color: $mid-gray;

$product-listing-card-overlay-link-zindex: 1;
$product-listing-card-thumbnail-border-radius: 8px;
$product-listing-card-grid-thumbnail-size: 72px;
$product-listing-card-grid-thumbnail-medium-size: 120px;
$product-listing-card-thumbnail-size: 120px;
$product-listing-card-thumbnail-medium-size: 162px;

$product-listing-card-padding-y: 17px;
$product-listing-card-padding-x: 20px;
$product-listing-card-footer-item-spacing: 30px;
$product-listing-card-tags-spacing: 5px;

//Local Mixins
@mixin alignContent ($align) {
    @if $align == 'center' {
        #{$namespace} {
            &_content {
                text-align: center;
            }
            &_header {
                text-align: center;
            }

            &_overview {
                margin-left: auto;
                margin-right: auto;
            }
            &_badges {
                justify-content: center;
            }

            &_footer {
                justify-content: center;

                &Credit {
                    justify-content: center;
                }
            }

            &_starsWrapper {
                justify-content: center;
                margin-left: $product-listing-card-footer-item-spacing / 2;
                margin-right: $product-listing-card-footer-item-spacing / 2;
            }
        }
    } @else if $align == 'right' {
        #{$namespace} {
            &_content {
                text-align: right;
            }
            &_header {
                text-align: right;
            }

            &_overview {
                margin-left: auto;
            }
            &_badges {
                justify-content: flex-end;
            }

            &_footer {
                justify-content: flex-end;

                &Credit {
                    justify-content: flex-end;
                }
            }

            &_starsWrapper {
                justify-content: flex-end;
                margin-right: 0;
            }
            &_compare {
                margin-left: $product-listing-card-footer-item-spacing;
            }
        }
    }
}

//Local Placeholders
%product-list-card-tags {
    display: inline-block;
    padding: 2px 5px;
    border-radius: 3px;
    line-height: 12px;
    font-size: $bodyFontSize7;
    font-weight: normal;
    text-align: center;
}

// Component Styles
#{$namespace} {
    &_productBadges {
        @extend %reset-list;
        display: flex;
        flex-wrap: wrap;

        &Item {
            margin-top: 6px;
            margin-right: 10px;

            @include media-md-down {
                margin-right: 6px;
            }
        }

        img {
            height: 30px;
            width: 30px;

            @include media-md-down {
                height: 22px;
                width: 22px;
            }
        }
        
        &--grid {
            margin-top: 9px;
        }
    }

    &_promoBadges {
        @extend %reset-list;
        &--list {
            margin-top: 6px;
            display: flex;
        }
    }

    &_wrapper {
        position: relative;
        height: 100%;
        z-index: 0;
    }

    &_container {
        @include text-6;
        position: relative;
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
        background-color: var(--card-container-bg-color, $product-listing-card-container-bgcolor);
        line-height: 19px;
        border: 1px solid var(--card-border-color, $product-listing-card-container-border-color);
        border-radius: var(--card-border-radius, 8px);
        transition: background-color 0.3s ease;

        &#{$container-list-view-selector} {
            padding: $product-listing-card-padding-y $product-listing-card-padding-x;

            @include media-md-up {
                flex-direction: row;
            }
        }

        &#{$container-grid-view-selector} {
            @include media-md-down {
                border: 0;

                // Disable hover effect when no border and padding in container
                &:hover {
                    background-color: transparent;
                }
            }
        }

        &--center {
            &#{$container-grid-view-selector} {
                @include alignContent('center');
            }
            &#{$container-list-view-selector} {
                @include media-md-down {
                    @include alignContent('center');
                }
            }
        }

        &--right {
            &#{$container-grid-view-selector} {
                @include alignContent('right');
            }
            &#{$container-list-view-selector} {
                @include media-md-down {
                    @include alignContent('right');
                }
            }
        }

        button, a, .checkbox_group {
            position: relative;
            z-index: $product-listing-card-overlay-link-zindex + 1;
        }

        &:hover {
            background-color: var(--card-container-bg-color-hover, $product-listing-card-container-bgcolor);

            #{$header-selector} {
                background-color: var(--card-header-bg-color-hover, transparent);
            }
        }
    }

    &_overlayLink {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: $product-listing-card-overlay-link-zindex;

        &Text {
            @extend %sr-only;
        }

        &:hover, &:focus {
            & + #{$container-selector} {
                background-color: var(--card-container-bg-color-hover, $product-listing-card-container-bgcolor);

                #{$header-selector} {
                    background-color: var(--card-header-bg-color-hover, transparent);
                }
            }
        }

        @include media-md-down {
            // Disable hover effect when no border and padding in container
            &:hover, &:focus {
                & + #{$container-grid-view-selector} {
                    background-color: transparent;
                }
            }
        }
    }

    &_header + &_content {
        $header-spacing: 8px;

        #{$container-grid-view-selector} & {
            margin-top: $header-spacing;
        }
        #{$container-list-view-selector} & {
            @include media-md-down {
                margin-top: $header-spacing;
            }
        }
    }

    &_header {
        background-color: var(--card-header-bg-color, transparent);

        &--with-bg-color {
            padding: 6px;
        }

        #{$container-list-view-selector} & {
            @include media-md-up {
                display: flex;
                flex-direction: column;
            }
        }

        #{$container-grid-view-selector} & {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;

            @include media-md-up {
                padding-top: 20px;
                padding-right: $product-listing-card-padding-x;
                padding-left: $product-listing-card-padding-x;
            }
        }

        @include media-md-down {
            flex-wrap: wrap;
        }
    }

    &_imageContainer {
        display: flex;
        width: $product-listing-card-thumbnail-size;
        height: $product-listing-card-thumbnail-size;
        &--medium {
            width: $product-listing-card-thumbnail-medium-size;
            height: $product-listing-card-thumbnail-medium-size;
            #{$container-grid-view-selector} & {
                width: $product-listing-card-grid-thumbnail-medium-size;
                height: $product-listing-card-grid-thumbnail-medium-size;
            }
        }

        #{$container-grid-view-selector} & {
            width: $product-listing-card-grid-thumbnail-size;
            height: $product-listing-card-grid-thumbnail-size;
        }
    }

    &_icon {
        display: inline-block;
        max-width: none;
        object-fit: cover;
        border-radius: $product-listing-card-thumbnail-border-radius;
        width: 100%;
        height: auto;
        margin-top: auto;
        margin-bottom: auto;

        &Container {
            #{$container-grid-view-selector} & {
                flex-grow: 1;
            }
        }
    }

    &_tags {
        display: flex;
        flex-direction: column;

        #{$container-grid-view-selector} & {
            padding-left: 10px;

            @include media-md-down {
                padding-left: 0;
                padding-top: 4px;
            }
        }
    }

    &_ribbon {
        @extend %product-list-card-tags;

        background-color: var(--card-ribbon-bg-color, $primary-color);
        color: var(--card-ribbon-color, $white);

        #{$container-list-view-selector} & {
            margin-top: 10px;

            @include media-md-up {
                border-radius: 1em;
            }
        }

        & + #{$namespace}_badges {
            margin-top: $product-listing-card-tags-spacing;
        }
    }

    &_content {
        display: flex;
        flex-direction: column;
        flex-grow: 1;

        #{$container-list-view-selector} & {
            @include media-md-up {
                padding-left: 22px;
            }
        }

        #{$container-grid-view-selector} & {
            @include media-md-up {
                padding-bottom: 17px;
                padding-right: $product-listing-card-padding-x;
                padding-left: $product-listing-card-padding-x;
            }
        }
    }

    &_information {
        flex-grow: 1;

        #{$container-list-view-selector} & {
            @include media-md-up {
                display: flex;
            }
        }

        #{$container-grid-view-selector} & {
            display: flex;
            flex-direction: column;
        }
    }

    &_description {
        flex-grow: 1;
    }

    &_title {
        @include title-3;
        display: block;
        margin: 0;
        line-height: 23px;
        color: var(--card-title-color, $title-color);

        @include media-md-down{
            @include title-4;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
        }
    }

    &_caption {
        margin-top: 6px;
        @include text-5;
        line-height: 17px;
        font-weight: bold;
    }

    &_overview {
        @include text-5;
        @include line-clamp;
        margin: 10px 0 0;

        #{$container-grid-view-selector} & {
            @include text-6;
            margin-top: 8px;
        }

        #{$container-list-view-selector} & {
            max-width: 620px;
        }

        p {
            margin-top: 0;

            &:last-child {
                margin-bottom: 0;
            }
        }

        @include media-md-down{
            @include text-6;
        }
    }

    &_badges {
        display: flex;
        flex-wrap: wrap;
        align-items: center;

        #{$container-grid-view-selector} & {
            flex-direction: column;
            align-items: center;
        }

        @include media-lg-down {
            display: inline-block;
        }
    }

    &_promoBadge {
        @extend %product-list-card-tags;
        display: block;
        margin: 0;

        #{$container-grid-view-selector} & {
            width: 100%;
            
            &:not(:first-of-type) {
                margin-top: $product-listing-card-tags-spacing;
            }
        }

        #{$container-list-view-selector} & {
            margin-top: $product-listing-card-tags-spacing;
            margin-right: $product-listing-card-tags-spacing;
        }
    }

    &_pricing {
        margin-top: 9px;

        #{$container-list-view-selector} & {
            @include media-md-up {
                margin: 0;
                padding-left: 30px;
            }
        }

        #{$container-grid-view-selector} & {
            @include text-5;
            font-weight: 700;

            @include media-md-down {
                @include text-6;
            }
        } 
    }

    &_footer {
        margin-top: 9px;

        &Credit {
            display: flex;
            line-height: 1;

            @include media-md-down {
                margin-top: 5px;
            }
        }

        @include media-md-up {
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            #{$container-grid-view-selector} & {
                justify-content: flex-end;
            }

            &Credit {
                flex-grow: 1;
                margin-right: $product-listing-card-footer-item-spacing;
            }
        }
    }

    &_starsWrapper {
        display: flex;

        //TODO: Find a way to hide rating average in the Rating component
        .rating {
            &_rating {
                display: none;
            }
        }

        @include media-md-up {
            #{$container-grid-view-selector} & {
                flex-grow: 1;
            }

            #{$container-list-view-selector} & {
                margin-right: 17px;
            }
        }
    }

    &_version + &_vendor {
        position: relative;
        margin-left: 5px;
        padding-left: 5px;
        &:before {
            content: "";
            position: absolute;
            top: 50%;
            left: 0;
            width: 1px;
            height: 65%;
            background-color: $deep-gray;
            transform: translateY(-50%);
        }
    }

    &_compare {
        @include media-lg-down {
            flex-basis: 100%;
            max-width: 100%;
            margin-top: 9px;
        }
        &--disabled {
            opacity: 0.5;
        }
    }
}
