@use "variables";

$vk-post-col-widths: (
  2: 16.66%,
  3: 25%,
  4: 33.3%,
  6: 50%,
  12: 100%
);
/* 各カラム接頭辞に対して「この幅を超えたら適用」となる下限側のしきい値
   下限側の比較なので、1 段階下のブレイクポイントの最大値を持たせている
   ========================================================================== */
$vk-post-col-breakpoints: (
  sm: variables.$xs-max,
  md: variables.$sm-max,
  lg: variables.$md-max,
  xl: variables.$lg-max,
  xxl: variables.$xl-max
);

@mixin vk-post-col-width-rules($prefix: null, $offset: 30px) {
  @each $col, $width in $vk-post-col-widths {
    $suffix: if($prefix == null, "", "#{$prefix}-");
    &-#{$suffix}#{$col} {
      width: calc(#{$width} - #{$offset});
    }
  }
}

/* ------------------------------------------- */
/* vk_post Layout
/* ------------------------------------------- */
/* vk_post common style
/* ------------------------------------------- */
/* Button display
/* ------------------------------------------- */
/* Main section 1 column adjustment
/* ------------------------------------------- */

/* ------------------------------------------- */
/* vk_post Layout
/* ------------------------------------------- */
/* If exclude the .vk_posts that, when you select the .media don't work */
.vk_posts .vk_post-col {
  // 5 と 7 は horizontal でのみ使用
  // 他のように -30px でないのは そもそも -30px 自体が vk_post の独自仕様であるため
  // horizontal では -30px をつける必要がないのでつけていない
  &-5 {
    width: 41.67%;
  }
  &-7 {
    width: 58.33%;
  }

  @include vk-post-col-width-rules(xs);

  @each $name, $breakpoint in $vk-post-col-breakpoints {
    @media ($breakpoint < width) {
      @include vk-post-col-width-rules($name);
    }
  }
}

/* ------------------------------------------- */
/* vk_post common style
/* ------------------------------------------- */
.vk_posts {
  margin-left: -15px;
  margin-right: -15px;
  display: flex;
  flex-wrap: wrap;
  clear: both; /* To be cope with inline image float and so on. */
}
.vk_post {
  margin-left: 15px;
  margin-right: 15px;
  a:hover {
    text-decoration: none;
  }
  &_body {
    box-sizing: border-box;
    font-size: 1rem;
  }
  &_imgOuter {
    position: relative;
    &_singleTermLabel {
      font-size: 10px;
      padding: 0.3em 0.8em;
      position: absolute;
      right: 0;
      top: 0;
      z-index: 100;
    }
    &.media-img {
      /* 
			overflow:hidden; がないと
			* G3
			* メディアレイアウト
			* フッターウィジェット無し
			* 投稿リストの最後の投稿の抜粋文字数が少ない
			の条件下で、画像が見えないエリアでhtmlエリアをはみ出して、
			htmlエリアがスクロール反応してしまい、下端にスクロールした時の挙動が不安定になる
			*/
      overflow: hidden;
    }
  }
  & &_title {
    font-size: 14px;
    line-height: 1.4;
    font-weight: bold;
    margin-bottom: 0;
    margin-top: 0;
    a {
      color: var(--vk-color-text-body);
    }
  }
  &_title_new {
    margin-left: 0.4em;
    font-size: 0.8em;
    white-space: nowrap;
    color: red;
  }
  & &_excerpt {
    margin: variables.$margin_post_item_element 0;
    font-size: 12px;
    line-height: 1.6;
    opacity: 0.8;
  }
  & &_dates {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 0.6em;
  }
  & &_date {
    font-size: var(--vk-font-size-xs);
    margin-top: variables.$margin_post_item_element_narrow;
    color: var(--vk-color-text-light);
  }
  &_author {
    margin: variables.$margin_post_item_element 0;
    &_image,
    &_name {
      display: inline-block;
      vertical-align: middle;
    }
    &_image {
      margin-right: 0.5rem;
      img {
        width: 24px;
        height: 24px;
        object-fit: cover;
        border-radius: 50%;
        object-position: 0px 0px;
        display: block;
      }
    }
    &_name {
      font-size: var(--vk-font-size-xs);
    }
  }
  &_taxonomies {
    margin-top: variables.$margin_post_item_element;
  }
  &_taxonomy {
    display: flex;
    flex-direction: row;
    margin: 0;
    font-size: var(--vk-font-size-xs);
    &:first-child {
      margin-top: 0;
    }
    &_title,
    &_terms {
      border: none;
      margin: 0 0 variables.$margin_post_item_element_narrow;
    }
    &_title {
      padding-left: 0;
      &_inner {
        display: block;
        border: variables.$border_primary;
        min-width: 8em;
        text-align: center;
        background-color: rgba(0, 0, 0, 0.05);
      }
    }
    &_terms {
      margin-top: 1px;
      padding-left: 10px;
      a {
        color: var(--vk-color-link);
        &:hover {
          opacity: 0.7;
        }
      }
    }
  }
  & &_btn {
    font-size: 12px;
    text-decoration: none;

    // カードの幅が狭い時にボタンが改行されてボタンの上のテキストと重なるため、通常のボタンより左右の余白を狭く変更
    padding-left: 1rem;
    padding-right: 1rem;
    white-space: nowrap;
  }
}

/* ------------------------------------------- */
/* image effect
/* ------------------------------------------- */
.vk_post {
  &_imgOuter {
    position: relative;
    background-size: cover;
    background-position: center 50%;
    border-bottom: variables.$border_image;
    & > a::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      background: rgba(0, 0, 0, 0);
      transition-duration: 0.3s;
    }
    & > a:hover::after {
      background: rgba(0, 0, 0, 0.5);
    }
    a {
      height: 100%;
    }
    &_img {
      position: absolute;
      left: -9999px;
    }
  }

  .vk_post_imgOuter {
    &:before {
      content: "";
      display: block;
      padding-top: 62%;
    }
  }

  &.card-horizontal {
    // テーマなどが bootstrap の grid を読み込むと、
    // horizontal に残っている col-5/col-7 のクラスにpadding をつけられてしまうので打ち消し
    // （ horizontal から col-5/col-7 のクラスを削除したらこちらも削除可 ）
    .vk_post-col-5,
    .vk_post-col-7 {
      padding: 0;
    }
    .vk_post_imgOuter {
      height: 100%;
      border-bottom: none;
      border-right: variables.$border_image;
      &:before {
        padding-top: 0;
      }
    }
    &.card-horizontal-reverse {
      .vk_post_imgOuter {
        border-right: none;
        border-left: variables.$border_image;
      }
      .card-horizontal-inner-row {
        flex-direction: row-reverse;
      }
    }
  }
  .card-horizontal-inner-row {
    display: flex;
  }
}

/* ------------------------------------------- */
/* Button display
/* ------------------------------------------- */
.vk_post-btn-display {
  .vk_post_body {
    position: relative;
    height: 100%;
  }
  .vk_post_btnOuter {
    position: absolute;
    bottom: 0;
  }
  &.media {
    .vk_post_body {
      padding-bottom: 45px;
    }
    .vk_post_btnOuter {
      width: 100%;
    }
  }
  &.card {
    .vk_post_body {
      padding-bottom: 65px;
    }
    .vk_post_btnOuter {
      width: calc(100% - 2.5rem);
      bottom: 1.25rem;
    }
  }
  .card-text,
  .media-text {
    &:nth-last-child(2) {
      margin-bottom: 0;
    }
  }
}
