// Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
// This software is released under MIT license.
// The full license information can be found in LICENSE in the root directory of this project.

// Backgrounds
$clr-table-bgcolor: $clr-white !default;
$clr-thead-bgcolor: $clr-near-white !default;

// Borders
$clr-tablerow-bordercolor: $clr-light-gray !default;
$clr-table-bordercolor: $clr-light-midtone-gray !default;
$clr-table-borderwidth: $clr-default-borderwidth !default;
$clr-table-borderstyle: $clr-table-borderwidth solid $clr-table-bordercolor !default;

// Etc.
$clr-table-fontsize: clr-getTypePropertyValueForDomElement(table_text, font-size);
$clr-table-lineheight: 0.583333rem !default;
$clr-table-cellpadding: 0.5rem !default;
$clr-table-smallpadding: 0.25rem !default;

$clr-table-lineheightPaddingShim: (1rem - $clr-table-lineheight)/2 !default;
$clr-table-topcellpadding: $clr-table-cellpadding - $clr-rem-1px !default;
$clr-table-bottomcellpadding: $clr-table-cellpadding - $clr-rem-1px !default;

$clr-table-topcellpadding-cmp: $clr-table-cellpadding/2 - $clr-rem-1px !default;
$clr-table-bottomcellpadding-cmp: $clr-table-cellpadding/2 - $clr-rem-1px !default;

// Border radius of corner cells needs to be slightly less than the table's,
// To make sure they correctly cover the whole area up to the border.
$clr-table-cornercellradius: calc(#{$clr-default-borderradius} - 1px) !default;

$clr-table--compact-rowHeight: 1rem !default;
$clr-table--compact-verticalPadding: ($clr-table--compact-rowHeight - $clr-table-lineheight)/2 !default;

// Mixin for basic table styles to be able to reuse them on non-table elements.
@mixin basic-table($table, $thead, $tbody, $tr, $th, $td) {
    #{$table} {
        border-collapse: separate;
        border: $clr-table-borderstyle;
        border-radius: $clr-global-borderradius;

        background-color: $clr-table-bgcolor;
        color: $clr-table-font-color;
        margin: 0;
        margin-top: 1rem;
        max-width: 100%;
        width: 100%;

        #{$th},
        #{$td} {
            font-size: $clr-table-fontsize;
            line-height: $clr-table-lineheight;
            border-top: $clr-table-borderwidth solid $clr-tablerow-bordercolor;
            padding: $clr-table-topcellpadding $clr-table-cellpadding $clr-table-bottomcellpadding;
            text-align: center;
            vertical-align: top;

            &.left {
                text-align: left;

                &:first-child {
                    padding-left: $clr-table-smallpadding;
                }
            }
        }

        #{$th} {
            @include clr-getTypePropertiesForDomElement(table_header, (color, font-size, font-weight, letter-spacing));

            background-color: $clr-thead-bgcolor;
            vertical-align: bottom;
            border-bottom: $clr-table-borderstyle;
            border-top: 0 none;
        }

        #{$tbody} #{$tr}:first-child #{$td} {
            border-top: 0 none;
        }

        // in the rare event we have more than one tbody element.
        #{$tbody} + #{$tbody} {
            border-top: $clr-table-borderstyle;
        }

        // Rounded corners on tables are a pain...
        #{$thead} #{$th} {
            &:first-child {
                border-radius: $clr-table-cornercellradius 0 0 0;
            }

            &:last-child {
                border-radius: 0 $clr-table-cornercellradius 0 0;
            }
        }

        #{$tbody}:last-child {
            #{$tr}:last-child {
                #{$td} {
                    &:first-child {
                        border-radius: 0 0 0 $clr-table-cornercellradius;
                    }

                    &:last-child {
                        border-radius: 0 0 $clr-table-cornercellradius 0;
                    }
                }
            }
        }
    }

    &#{$table}-compact {
        #{$th},
        #{$td} {
            padding-top: calc(#{$clr-table--compact-verticalPadding} + 1px);
            padding-bottom: calc(#{$clr-table--compact-verticalPadding});
        }
    }
}
