@import '../../../styles/definitions/breakpoints';
@import '../../../styles/definitions/colors';
@import '../../../constants/modifiers';
@import '../../../styles/mixins';

$namespace: ".tile";

// Modifiers selectors
$tile-item-classic-selector: #{$namespace}_item--classic;
$tile-item-square-selector: #{$namespace}_item--square;
$tile-item-tall-selector: #{$namespace}_item--tall;
$tile-item-graphic-selector: #{$namespace}_item--graphic;
$tile-item-horizontal-selector: #{$namespace}_item--horizontal;

$tile-item-large-selector: #{$namespace}_item--large;
$tile-item-medium-selector: #{$namespace}_item--medium;
$tile-item-small-selector: #{$namespace}_item--small;

$tile-border-radius: var(--border-radius, 8px);
$tile-card-border-radius: var(--card-border-radius, 8px);

$tile-image-small: 48px;
$tile-image-medium: 82px;
$tile-image-large: 112px;
$tile-image-ultralarge: 140px;

$tile-tags-spacing: 5px;

// Component Styles
#{$namespace} {
    &_item {
        position: relative;
        height: var(--tile-height);
        color: $deep-gray;

        &--horizontal {
            flex-direction: row;
        }

        &--square, &--tall, &--graphic {
            border-radius: $tile-card-border-radius;
            padding: 0;
            overflow: hidden;
        }
        
        &--with-shadow {
            &#{$namespace}_item--square, &#{$namespace}_item--tall, &#{$namespace}_item--graphic {
                box-shadow: 0 2px 5px 0 rgba(0,1,0,0.25);
            }
        }

        &--tall {
            background: var(--tile-background-color);
        }
    }
    &_overlay {
        &Link {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            z-index: 1;
        }
        &Label {
            @extend %sr-only;
        }
    }
    &_content {
        display: flex;
        flex-direction: column;
        height: 100%;
        #{$tile-item-square-selector} &, #{$tile-item-tall-selector} &, #{$tile-item-graphic-selector} & {
            background: var(--text-background-color);
        }

        #{$tile-item-horizontal-selector} & {
            flex-direction: row;
        }
    }
    &_imageWrapper {
        display: flex;
        align-items: center;
        flex-shrink: 0;
        border-radius: $tile-border-radius;
        overflow: hidden;
        background: var(--tile-background-color);
        position: relative;

        #{$tile-item-square-selector} &, #{$tile-item-tall-selector} &, #{$tile-item-graphic-selector} & {
            border-radius: 0;
            justify-content: center;
        }
        #{$tile-item-horizontal-selector} & {
            width: $tile-image-medium;
            height: $tile-image-medium;
            margin-right: 18px;
        }
        #{$tile-item-horizontal-selector}#{$tile-item-large-selector} & {
            width: $tile-image-ultralarge;
            height: $tile-image-ultralarge;
            margin-right: 26px;
        }

        #{$tile-item-tall-selector} & {
            justify-content: left;
        }
    }

    &_image {
        width: 100%;
        height: 100%;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
        
        /* the padding makes the image container a square */
        padding-bottom: 100%;

        #{$tile-item-square-selector} &, #{$tile-item-tall-selector} & {
            border-radius: $tile-border-radius;
        }

        #{$tile-item-square-selector} &, #{$tile-item-tall-selector} & {
            width: $tile-image-medium;
            height: $tile-image-medium;
            margin: calc($tile-image-medium / 3.4);

            /* with layout `square` we have a fixed height of the parent */
            padding-bottom: 0;
        }
        #{$tile-item-square-selector}#{$tile-item-large-selector} &, #{$tile-item-tall-selector}#{$tile-item-large-selector} &  {
            width: $tile-image-large;
            height: $tile-image-large;
            margin: calc($tile-image-large / 3.4);
        }
        #{$tile-item-tall-selector}#{$tile-item-small-selector} &, #{$tile-item-square-selector}#{$tile-item-small-selector} & {
            width: $tile-image-small;
            height: $tile-image-small;
            margin: calc($tile-image-small / 3.4);
        }
    }

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

        #{$tile-item-square-selector} &, #{$tile-item-graphic-selector} & {
            padding: 10px 24px 7px;
        }

        #{$tile-item-small-selector}#{$tile-item-square-selector} &, #{$tile-item-medium-selector}#{$tile-item-square-selector} &  {
            // on mobile we need to reduce padding
            @include media-sm-down {
                padding: 10px 12px 7px;
            }
        }

        #{$tile-item-tall-selector} & {
            padding: 10px 10px 7px;
        }

        #{$tile-item-small-selector}#{$tile-item-graphic-selector} & {
            padding: 10px 14px 7px;
        }
        
        #{$tile-item-large-selector}#{$tile-item-graphic-selector} & {
            display: none;
        }
    }

    &_vendor {
        @include text-7;
        margin: 4px 0 10px;
    }

    &_vendorWrapper {
        display: flex;
        margin-top: 10px;
        & > div {
            margin-right: 16px;
        }
    }

    &_detailsWrapper {
        flex-grow: 1;
        padding-bottom: 7px;
    }

    &_pricing {
        #{$tile-item-horizontal-selector} & {
            display: none;
        }
    }
    
    &_name {
        @include title-3;
        line-height: 23px;
        margin-top: 10px;
        word-wrap: break-word;
        @include line-clamp(3);

        #{$tile-item-classic-selector} & {
            margin-top: 14px;
        }
    }
    &_pricing {
        @include text-6;
        font-weight: bold;
        line-height: 19px;
        margin: 7px 0;
        
        #{$tile-item-graphic-selector} & {
            display: none;
        }
    }
    &_description {
        @include text-6;
        @include color-darkGray;
        @include line-clamp(2);
        position: relative;

        font-weight: normal;
        line-height: 1.4em;
        margin-top: 7px;

        &:after {
            content: "";
            width: 2.5rem;
            height: 15px;
            position: absolute;
            bottom: 0;
            right: 0;
        }

        #{$tile-item-square-selector} & {
            @include text-6;
            line-height: 1.4em;
        }
    }
    &_rating {
        @include text-6;
        @include color-darkGray;
        min-height: 22px;
    }

    &_buyNow {
        display: none;
        #{$tile-item-tall-selector} & {
            @include title-6;
            font-weight: 500;

            display: block;
            margin: 10px -10px 0;
            padding: 10px 0 3px;
            border-top: 1px rgba(0, 1, 0, 0.07) solid;
            line-height: 15px;
            text-align: center;
            @include link-colors($link-text-color);
        }
    }

    &_categoriesWrapper {
        @include text-6;
        span {
            margin-right: 24px;
        }
    }

    &_tags {
        display: flex;
        flex-wrap: wrap;
        margin-bottom: $tile-tags-spacing;
    }

    &_ribbon {
        display: flex;
        margin-top: $tile-tags-spacing;
        margin-right: $tile-tags-spacing;
    }

    &_ribbonWrapper {
        color: var(--card-ribbon-color, $white);
        background-color: var(--card-ribbon-bg-color, $primary-color);
        border: 0;
    }

    &_merchandisingBadges,
    &_tags {
        @extend %reset-list;
    }

    &_badge {
        display: flex;
        margin-top: $tile-tags-spacing;

        &List {
            display: flex;
            flex-wrap: wrap;
            align-items: flex-start;
        }

        &:not(:last-of-type) {
            margin-right: $tile-tags-spacing;
        }
    }
    &_merchandisingBadges {
        display: flex;
        flex-wrap: wrap;
        margin-top: 10px;
    }

    &_merchandisingBadgeItem {
        margin-top: 8px;
        margin-right: 8px;
        height: 24px;
        width: 24px;
    }
}
