/*
 * https://github.com/morethanwords/tweb
 * Copyright (C) 2019-2021 Eduard Kuzmenko
 * https://github.com/morethanwords/tweb/blob/master/LICENSE
 */

@use "sass:math";

$row-border-radius: $border-radius-medium;

.row {
  min-height: 3.5rem;
  position: relative;
  padding-block: .4375rem;
  padding-inline: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  // align-items: flex-start;

  &.no-subtitle,
  &.row-small {
    min-height: 3rem;
    padding-top: .1875rem;
    padding-bottom: .1875rem;
  }

  @include animation-level(2) {
    transition: opacity var(--transition-standard-in);
  }

  &.is-disabled {
    pointer-events: none !important;
    opacity: var(--disabled-opacity);
  }

  &.is-fake-disabled {
    .row-row {
      opacity: var(--disabled-opacity);
    }

    .checkbox-field-toggle {
      --primary-color: var(--secondary-color);
    }
  }

  &.no-wrap {
    padding-top: 0 !important;
    padding-bottom: 0 !important;

    br {
      content: " ";

      &:after {
        content: " ";
      }
    }
  }

  a {
    position: relative;
    z-index: 1;
    pointer-events: all;
  }

  &-title-row,
  & > &-title {
    order: 0;
  }

  &-grid {
    display: grid;
    justify-content: initial;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas: "left title right" "left subtitle right";
    align-items: center;
    padding-inline-start: 1rem !important;

    &.row-with-padding {
      grid-template-columns: 3.5rem 1fr auto;
    }

    &.no-subtitle {
      grid-template-areas: "left title right";
      grid-template-rows: auto;

      .row-title {
        align-self: unset;
      }
    }

    &.with-midtitle {
      grid-template-areas: "left title right" "left midtitle right" "left subtitle right";
      grid-template-rows: auto auto auto;
    }

    .row-title {
      grid-area: title;
      align-self: flex-end;
    }

    .row-subtitle {
      grid-area: subtitle;
      align-self: flex-start;
    }

    .row-midtitle {
      grid-area: midtitle;
      align-self: flex-start;
    }

    .checkbox-field {
      --offset-left: 0 !important;
      grid-area: left;
      width: 3.5rem;
      position: relative !important;
      margin: 0 !important;
      padding: 0 !important;
    }

    // .row-media {
    //   grid-area: left;
    //   margin-inline-start: -1rem !important;
    //   // position: relative !important;
    //   // inset-inline-start: auto !important;
    // }

    .row-right {
      margin-inline-start: 1rem;
      grid-area: right;
    }
  }

  &-big {
    min-height: 4.5rem;
    padding-block: .5625rem;
    padding-inline: 1rem .75rem;
  }

  &-row {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .row-title,
    .row-subtitle {
      overflow: visible;
      text-overflow: ellipsis;
      white-space: nowrap;
      min-width: 0;
      flex: 1 1 auto;

      .peer-title {
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }

  &-subtitle-row,
  & > &-subtitle {
    order: 1;
  }

  // &-title,
  // &-title-row,
  // &-subtitle {
  //   pointer-events: none;
  // }

  &-title {
    color: var(--primary-text-color);
    font-size: var(--font-size);
    line-height: var(--line-height);

    @include text-overflow(false);

    &-right {
      &-secondary {
        color: var(--secondary-text-color);
      }

      .input-clear {
        color: inherit;
        text-align: right;
        pointer-events: all;
        cursor: text;
      }
    }

    &-row {
      &.with-delimiter {
        .row-title:first-child {
          border-right: 1px solid var(--border-color);
        }
      }
    }

    &-badge {
      text-transform: uppercase;
      border-radius: 4px;
      background-color: var(--primary-color);
      color: #fff;
      padding: .1875rem .3125rem;
      font-size: 75%;
      margin-inline-start: .375rem;
      font-weight: var(--font-weight-bold);
      display: inline-block;
      line-height: 1;
      position: relative;
      top: -1px;
    }
  }

  &-title-right,
  &-subtitle-right {
    flex: 0 0 auto !important;
    margin-inline-start: 1rem;
  }

  &-title,
  &-subtitle,
  &-midtitle {
    position: relative;
    pointer-events: none;
  }

  &-midtitle {
    font-size: var(--font-size-14);
    line-height: 20px;
    margin: 1px 0 -1px;
    order: 1;
  }

  &-with-padding {
    padding-inline-start: 4.5rem;

    @include respond-to(handhelds) {
      padding-inline-start: 4rem;
    }

    /* .row-title */
    .row-icon {
      position: absolute;
      inset-inline-start: 1rem;
      font-size: 1.5rem;
      color: var(--secondary-text-color);
      pointer-events: none;
      z-index: 1;

      // margin-top: -.125rem;
      top: 50%;
      transform: translateY(-50%);

      &-premium-color {
        color: var(--primary-color);
      }

      &-custom-color {
        color: var(--custom-icon-color);
      }

      &-stars-color {
        color: var(--star-golden-color);
      }
    }

    &:not(.row-with-icon) .row-icon {
      display: none;
    }

    // .row-subtitle:not(:empty):not(.hide) + .row-title.tgico:before {
    //   margin-top: .25rem;
    // }
  }

  &-clickable {
    cursor: pointer;
    overflow: hidden;

    @include respond-to(not-handhelds) {
      border-radius: $row-border-radius;
    }
  }

  &-sortable {
    .row-title,
    .row-subtitle {
      padding-inline-end: 2.5rem;
    }

    &-icon {
      font-size: 1.5rem;
      height: 1.5rem;
      line-height: 1;
      color: var(--secondary-text-color);
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      inset-inline-end: .75rem;
      pointer-events: none;
      opacity: 0;
    }

    &.cant-sort {
      .row-sortable-icon {
        display: none;
      }
    }

    &.is-dragging {
      background-color: var(--surface-color) !important;
      z-index: 1;
      // box-shadow: 0 0 3px 2px rgba(0, 0, 0, $hover-alpha);
      // &:after {
      //   content: " ";
      //   position: absolute;
      //   top: 0;
      //   right: 0;
      //   bottom: 0;
      //   left: 0;
      //   background-color: var(--surface-color);
      //   z-index: -1;
      // }

      @include hover() {
        background-color: var(--light-filled-secondary-text-color) !important;
      }
    }

    @include hover() {
      .row-sortable-icon {
        opacity: 1;
      }
    }

    .is-reordering & {
      @include animation-level(2) {
        transition: transform var(--transition-standard-in);
      }
    }
  }

  .radio-field-main, 
  .checkbox-field {
    padding-inline-start: 3.375rem;
    margin-inline-start: -3.375rem;
  }

  .radio-field,
  .radio-field:not(.radio-field-right) .radio-field-main,
  .checkbox-field {
    position: unset;
  }
  
  .radio-field,
  .checkbox-field,
  .offset-left {
    --offset-left: 1rem;
  }

  .radio-field {
    margin-top: 0;
    margin-bottom: 0;
  }

  .checkbox-field {
    margin-top: 0;
    margin-inline-end: 0;
    margin-bottom: 0;
    height: auto;

    .checkbox-caption {
      padding-inline-start: 0;
      white-space: pre-wrap;
      overflow: unset;
      text-overflow: unset;
    }

    &-toggle {
      margin-inline: .125rem .125rem;
      padding: 0;
    }

    &-absolute {
      position: absolute;
      margin: 0 !important;
      padding: 0 !important;
      left: 0;
    }

    &-round {
      .checkbox-box-border {
        z-index: unset;
      }
    }
  }

  &-subtitle {
    color: var(--secondary-text-color) !important;
    font-size: var(--font-size-14) !important;
    line-height: var(--line-height-14);
    margin-top: .1875rem;

    // &:empty {
    //   display: none;
    // }
  }

  &-media {
    width: 2.25rem !important;
    height: 2.25rem !important;
    position: absolute !important;
    margin: 0 !important;
    inset-inline-start: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;

    &-small {
      width: 2rem !important;
      height: 2rem !important;
      inset-inline-start: .75rem !important;
    }

    &-40 {
      width: 2.625rem !important;
      height: 2.625rem !important;
      inset-inline-start: .75rem !important;
    }

    &-abitbigger {
      width: 2.625rem !important;
      height: 2.625rem !important;
      inset-inline-start: .75rem !important;
    }

    &-big {
      width: 3rem !important;
      height: 3rem !important;
      inset-inline-start: .5rem !important;
    }

    &-bigger {
      width: 3.375rem !important;
      height: 3.375rem !important;
      inset-inline-start: .5625rem !important; // it's wrong but old chatlist has it
    }
  }

  &.menu-open {
    background-color: var(--light-secondary-text-color);
  }

  &.accordion-toggler {
    .checkbox-field-toggle {
      pointer-events: all !important;
    }
  }
}
