/* Copyright (c) Fortanix, Inc.
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@use '../../../styling/defs.scss' as bk;
@use '../../../typography/Heading/Heading.mixins.scss' as heading;

@mixin bk-card($name: bk-card) {
  --bk-card-background-color: #{bk.$theme-card-background-default};
  --bk-card-border-color: #{bk.$theme-card-border-default};
  --bk-card-inset: #{bk.$spacing-4};
  
  overflow: hidden;
  
  &:where(:not(.#{$name}--flat)) {
    //min-block-size: bk.$spacing-16;
    padding: var(--bk-card-inset);
    padding-block-end: bk.$spacing-8;
    
    background: var(--bk-card-background-color);
    border: bk.$size-1 solid var(--bk-card-border-color);
    border-radius: bk.$radius-3;
  }
  
  @include bk.flex-column;
  
  .#{$name}__heading {
    &.#{$name}__heading--link {
      align-self: start;
      max-inline-size: 100%;
      cursor: pointer;
      @include heading.h5;
    }
    
    margin-block-end: bk.$spacing-5;
    
    // Note: use `:has()` here so that we don't break existing usages of this component without the additional
    // `<span>` nested elements
    &:not(:has(.#{$name}__heading__content)) {
      @include bk.text-one-line;
    }
    &:has(.#{$name}__heading__content) {
      display: flex;
      align-items: center;
      gap: 0.8ch;
      
      .#{$name}__heading__icon { --keep: ; }
      
      .#{$name}__heading__content {
        @include bk.text-one-line;
      }
    }
  }
  
  &.#{$name}--flat > .#{$name}__heading {
    margin-block-end: bk.$spacing-1;
  }
  
  // Separators
  hr {
    margin-block: bk.$spacing-3;
    border: none;
    border-block-start: bk.rem-from-px(1) solid bk.$theme-rule-default;
  }
}

@layer baklava.components {
  .bk-card {
    @include bk.component-base(bk-card);
    @include bk-card;
  }
}
