@use '../common/variables';
@use '../common/mixins';
@use '../utilities/text';
@use '../components/buttons';

// —————————————————————————————————————————————————————————————————
// elements
// size
// fill
// direction
// align
// transparent
// hasShadow
// —————————————————————————————————————————————————————————————————

// —————————————————————————————————————————————————————————————————
// elements
// —————————————————————————————————————————————————————————————————

.card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  overflow: hidden; // hide corners when CardMedia has fullWidth prop set to true
  
  &:not(.card-transparent) {
    background-color: variables.$background-paper;
    border: variables.$border;
  }

  &_media,
  &_header,
  &_content,
  &_actions {
    width: 100%;
  }

  &_media {
    
    &Inner {
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center center;
      width: 100%;
      height: 100%;
      background-color: variables.$overlay;
      overflow: hidden;
      padding-bottom: 50%;
      
      .card-transparent & {
        background-color: variables.$overlay-contrast;
      }
    }
  }

  &_header {

    @include mixins.responsive(down, tablet) {
      display: flex;
      flex-direction: column;
    }
  }

  &_headerActions {
    @extend %buttons;
    width: fit-content;
    justify-content: flex-end;
    
    @include mixins.responsive(up, tablet) { float: right; }
    @include mixins.responsive(down, tablet) { order: 4; }
  }

  &_label,
  &_title {
    font-weight: variables.$font-bold;
  }

  &_title {
    line-height: 1.25;
  }
    
  &_content {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;

    &-fullWidth {

      .card > &.card_content {
        padding-right: 0;
        padding-left: 0;
      }
    }
  }

  &_actions {
    display: flex;
    justify-content: space-between;

    >*:only-child {
      margin-left: auto;
    }

    &-portrait {
      flex-direction: column;

      .button {
        width: 100%;
      }

      >*:not(:last-child) {
        margin-bottom: 1rem;
      }
    }

    .buttons {
      width: fit-content;
    }
  }
}

// —————————————————————————————————————————————————————————————————
// size
// —————————————————————————————————————————————————————————————————

@mixin card-size($value, $size) {

  &:not(.card-transparent) {
    border-radius: calc($size/2);
  } 

  > .card_media,
  > .card_header,
  > .card_content,
  > .card_actions {
    padding: $size;

    &:not(:first-child) {
      padding-top: 0;
    }
  }

  > .card_actions {
    margin-top: auto;
  }

  &.card-transparent {

    > .card_media,
    > .card_header,
    > .card_content,
    > .card_actions {
      padding: 0;
        
      &:not(:first-child) {
        padding-top: $size;
      }
    }

    > .card_media .card_mediaInner {
      border-radius: calc($size/2);
    }
  }

  .card_media-fullWidth {
    padding-right: 0;
    padding-top: 0;
    padding-left: 0;
  }

  .card {

    &_headerActions {

      @include mixins.responsive(down, tablet) {
        margin-top: $size*0.75;
      }
    }

    &_label {
      @if $value == xs { font-size: variables.$overline-size; }
      @else if $value == sm { font-size: variables.$overline-size; }
      @else if $value == md { font-size: variables.$overline-size; }
      @else if $value == lg { font-size: variables.$caption-size; }
      @else if $value == xl { font-size: variables.$body-size; }
      margin-bottom: calc($size / 4);
    }

    &_title {
      @if $value == xs { font-size: variables.$body-size; }
      @else if $value == sm { font-size: variables.$subtitle-size; }
      @else if $value == md { font-size: variables.$h6-size; }
      @else if $value == lg { font-size: variables.$h5-size; }
      @else if $value == xl { font-size: variables.$h4-size; }
    }

    &_subtitle {
      @if $value == xs { font-size: variables.$caption-size; }
      @else if $value == sm { font-size: variables.$body-size; }
      @else if $value == md { font-size: variables.$subtitle-size; }
      @else if $value == lg { font-size: variables.$h6-size; }
      @else if $value == xl { font-size: variables.$h5-size; }
      margin-top: calc($size / 3);
    }

    &_mediaInner {
      border-radius: calc($size/8);
    }
  }

  > .card_media-fullWidth .card_mediaInner {
    border-radius: 0;
  }

  &.card-transparent > .card_media-fullWidth .card_mediaInner {
    border-radius: calc($size/2);
  }

  &.card-landscape {

    > .card_media,
    > .card_header,
    > .card_content,
    > .card_actions {
      padding-top: $size;

      &:not(:first-child) {
        padding-left: 0;
      }
    }

    > .card_actions {
      margin-left: auto;
      flex-direction: column;
      justify-content: flex-start;
    }

    &.card-transparent {

      > .card_media,
      > .card_header,
      > .card_content,
      > .card_actions {
        padding: 0;
        
        &:not(:first-child) {
          padding-left: $size;
        }
      }

      > .card_media .card_mediaInner {
        border-radius: calc($size/2);
      }
    }

    .card_media-fullWidth {
      padding-top: 0;
      padding-bottom: 0;
      padding-left: 0;
    }
  }
}

.card {
  @include card-size(md, 1.5rem);
  &-xs.card { @include card-size(xs, .75rem); }
  &-sm.card { @include card-size(sm, 1rem); }
  &-lg.card { @include card-size(lg, 2rem); }
  &-xl.card { @include card-size(xl, 2.5rem); }
}

// —————————————————————————————————————————————————————————————————
// fill
// —————————————————————————————————————————————————————————————————

// the fill styling is handled by the color utility file

// —————————————————————————————————————————————————————————————————
// direction
// —————————————————————————————————————————————————————————————————

// most of the direction styling is handled by the size mixin

.card-landscape {
  flex-direction: row;

  .card_media {
    flex-basis: 0;
  }
}

// —————————————————————————————————————————————————————————————————
// align
// —————————————————————————————————————————————————————————————————

.card {

  &-center { text-align: center; }
  &-right { text-align: right; }
}
// —————————————————————————————————————————————————————————————————
// transparent
// —————————————————————————————————————————————————————————————————

// the transparent styling is handled by the size mixin

// —————————————————————————————————————————————————————————————————
// hasShadow
// —————————————————————————————————————————————————————————————————

// the shadow styling is handled by the size mixin

.card-hasShadow {
  box-shadow: 0 1px .5rem rgba(variables.$text, 0.15);
}