@use '_variables' as *;
@use '_mixins' as *;
@use '_icons' as *;

/* stylelint-disable */
@import '~primeng/resources/primeng.css';

// Override primeng style we don't want
input[type=button] {
  border-radius: inherit;
}

p-table .p-datatable-header .caption {
  margin-bottom: 15px;
}

// Taken from old nova light theme

body .p-disabled {
  opacity: 0.5;
}

// Checkbox
body .p-checkbox {
  display: inline-block;
  vertical-align: middle;
  margin: 0;
  width: 20px;
  height: 20px;
}
body .p-checkbox .p-checkbox-box {
  border: 1px solid #a6a6a6;
  background-color: #ffffff;
  width: 20px;
  height: 20px;
  text-align: center;
  border-radius: 3px;
  transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
body .p-checkbox .p-checkbox-box:not(.p-disabled):hover {
  border-color: #212121;
}
body .p-checkbox .p-checkbox-box .p-checkbox-icon {
  overflow: hidden;
  position: relative;
  font-size: 18px;
}

// Paginator
body .p-paginator {
  background-color: #f4f4f4;
  border: 1px solid #c8c8c8;
  padding: 0;
}
body .p-paginator .p-paginator-first,
body .p-paginator .p-paginator-prev,
body .p-paginator .p-paginator-next,
body .p-paginator .p-paginator-last {
  color: #848484;
  height: 2.286em;
  min-width: 2.286em;
  border: 0 none;
  line-height: 2.286em;
  padding: 0;
  margin: 0;
  vertical-align: top;
  transition: box-shadow 0.2s;
  border-radius: 0;
}
body .p-paginator .p-paginator-first:not(.p-disabled):not(.p-highlight):hover,
body .p-paginator .p-paginator-prev:not(.p-disabled):not(.p-highlight):hover,
body .p-paginator .p-paginator-next:not(.p-disabled):not(.p-highlight):hover,
body .p-paginator .p-paginator-last:not(.p-disabled):not(.p-highlight):hover {
  background-color: #e0e0e0;
  color: #333333;
}
body .p-paginator .p-paginator-first:focus,
body .p-paginator .p-paginator-prev:focus,
body .p-paginator .p-paginator-next:focus,
body .p-paginator .p-paginator-last:focus {
  outline: 0 none;
  outline-offset: 0;
  box-shadow: 0 0 0 0.2em pvar(--mainColorLightest);
}
body .p-paginator .p-paginator-current {
  color: #333333;
  height: 2.286em;
  min-width: 2.286em;
  line-height: 2.286em;
}
body .p-paginator .p-dropdown .p-dropdown-trigger, body .p-paginator .p-dropdown .p-dropdown-label {
  color: #848484;
}
body .p-paginator .p-dropdown:hover .p-dropdown-trigger, body .p-paginator .p-dropdown:hover .p-dropdown-label {
  color: #333333;
}
body .p-paginator .p-paginator-first:before {
  position: relative;
  top: 1px;
}
body .p-paginator .p-paginator-prev:before {
  position: relative;
  top: 1px;
}
body .p-paginator .p-paginator-next:before {
  position: relative;
  top: 1px;
}
body .p-paginator .p-paginator-last:before {
  position: relative;
  top: 1px;
}
body .p-paginator .p-paginator-pages {
  vertical-align: top;
  display: inline-block;
  padding: 0;
}
body .p-paginator .p-paginator-pages .p-paginator-page {
  color: #848484;
  height: 2.286em;
  min-width: 2.286em;
  border: 0 none;
  line-height: 2.286em;
  padding: 0;
  margin: 0;
  vertical-align: top;
  transition: box-shadow 0.2s;
  border-radius: 0;
}
body .p-paginator .p-paginator-pages .p-paginator-page:not(.p-highlight):hover {
  background-color: #e0e0e0;
  color: #333333;
}
body .p-paginator .p-paginator-pages .p-paginator-page:focus {
  outline: 0 none;
  outline-offset: 0;
  box-shadow: 0 0 0 0.2em pvar(--mainColorLightest);
}
body .p-paginator .p-dropdown {
  @include margin-left(0.5em);

  height: 2.286em;
  min-width: auto;
}

// Dropdown

body .p-dropdown {
  background: #ffffff;
  border: 1px solid #a6a6a6;
  transition: border-color 0.2s, box-shadow 0.2s;
  border-radius: 6px;
}
body .p-dropdown:not(.p-disabled):hover {
  border-color: #212121;
}
body .p-dropdown:not(.p-disabled).p-focus {
  outline: 0 none;
  outline-offset: 0;
  box-shadow: 0 0 0 0.2em pvar(--mainColorLightest);
  border-color: pvar(--mainColor);
}
body .p-dropdown.p-dropdown-clearable .p-dropdown-label {
  @include padding-right(0);
}
body .p-dropdown .p-dropdown-label {
  background: transparent;
  border: 0 none;
}
body .p-dropdown .p-dropdown-label.p-placeholder {
  color: #6c757d;
}
body .p-dropdown .p-dropdown-label:enabled:focus {
  outline: 0 none;
  box-shadow: none;
}

body .p-dropdown .p-dropdown-trigger {
  background-color: transparent;
  width: 2rem;
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
  color: #848484;
}
body .p-dropdown .p-dropdown-clear-icon {
  color: #848484;
  right: 2rem;
}
body .p-dropdown.p-dropdown-clearable .p-dropdown-label {
  @include padding-right(4em);
}
body .p-dropdown-panel {
  background-color: #ffffff;
  box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.16);
  border: 0 none;
  border-radius: 6px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
body .p-dropdown-panel .p-dropdown-filter-container {
  padding: 0.429em 0.857em 0.429em 0.857em;
  border-bottom: 1px solid #eaeaea;
  color: #333333;
  background-color: #ffffff;
  margin: 0;
}
body .p-dropdown-panel .p-dropdown-filter-container .p-dropdown-filter {
  @include padding-right(2em);

  width: 100%;
}
body .p-dropdown-panel .p-dropdown-filter-container .p-dropdown-filter-icon {
  top: 50%;
  margin-top: -0.5em;
  right: 1.357em;
  color: pvar(--mainColor);
}
body .p-dropdown-panel .p-dropdown-items {
  padding: 0;
}
body .p-dropdown-panel .p-dropdown-items .p-dropdown-item, body .p-dropdown-panel .p-dropdown-items .p-dropdown-item-group {
  margin: 0;
  padding: 0.429em 0.857em;
  border: 0 none;
  color: #333333;
  background-color: transparent;
  -moz-border-radius: 0;
  -webkit-border-radius: 0;
  border-radius: 0;
}
body .p-dropdown-panel .p-dropdown-items .p-dropdown-item.p-highlight,
body .p-dropdown-panel .p-dropdown-items .p-dropdown-item-group.p-highlight {
  color: #ffffff;
  background-color: pvar(--mainColor);
}
body .p-dropdown-panel .p-dropdown-items .p-dropdown-item:not(.p-highlight):not(.p-disabled):hover,
body .p-dropdown-panel .p-dropdown-items .p-dropdown-item-group:not(.p-highlight):not(.p-disabled):hover {
  color: #333333;
  background-color: #eaeaea;
}
body p-dropdown.ng-dirty.ng-invalid > .p-dropdown {
  border: 1px solid #a80000;
}

// p-toast
body .p-toast .p-toast-message {
  box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.16);
  margin: 0 0 1em 0;
}

// p-calendar
body .p-datepicker {
  padding: 0.857em;
  min-width: 20em;
  background-color: #ffffff;
  color: #333333;
  border: 1px solid #a6a6a6;
}

body .p-datepicker:not(.p-datepicker-inline) {
  border: 1px solid #c8c8c8;
  box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.16);
}
body .p-datepicker:not(.p-disabled) .p-datepicker-header .p-datepicker-prev:focus,
body .p-datepicker:not(.p-disabled) .p-datepicker-header .p-datepicker-next:focus {
  outline: 0 none;
  outline-offset: 0;
  box-shadow: 0 0 0 0.2em pvar(--mainColorLightest);
}
body .p-datepicker:not(.p-disabled) table td a:not(.p-highlight):not(.p-highlight):hover {
  background-color: #eaeaea;
}
body .p-datepicker:not(.p-disabled) .p-monthpicker a.p-monthpicker-month:not(.p-highlight):hover {
  background-color: #eaeaea;
}
body .p-datepicker .p-datepicker-header {
  padding: 0.429em 0.857em 0.429em 0.857em;
  background-color: #ffffff;
  color: #333333;
  -moz-border-radius: 0;
  -webkit-border-radius: 0;
  border-radius: 0;
}
body .p-datepicker .p-datepicker-header .p-datepicker-prev,
body .p-datepicker .p-datepicker-header .p-datepicker-next {
  cursor: pointer;
  top: 0;
  color: #a6a6a6;
  transition: color 0.2s, box-shadow 0.2s;
}
body .p-datepicker .p-datepicker-header .p-datepicker-title {
  margin: 0;
  padding: 0;
  line-height: 1;
}
body .p-datepicker .p-datepicker-header .p-datepicker-title select {
  margin-top: -0.35em;
  margin-bottom: 0;
  transition: color 0.2s, box-shadow 0.2s;
}
body .p-datepicker .p-datepicker-header .p-datepicker-title select:focus {
  outline: 0 none;
  outline-offset: 0;
  box-shadow: 0 0 0 0.2em pvar(--mainColorLightest);
}
body .p-datepicker .p-datepicker-header .p-datepicker-title .p-datepicker-month {
  @include margin-right(0.5rem);
}
body .p-datepicker table {
  font-size: 14px;
  margin: 0.857em 0 0 0;
}
body .p-datepicker table th {
  padding: 0.5em;
}
body .p-datepicker table th.p-datepicker-weekheader {
  border-right: 1px solid #a6a6a6;
}
body .p-datepicker table td {
  padding: 0.5em;
}
body .p-datepicker table td > a,
body .p-datepicker table td > span {
  display: block;
  text-align: center;
  color: #333333;
  padding: 0.5em;
  transition: box-shadow 0.2s;
  border-radius: 3px;
}
body .p-datepicker table td > a.p-highlight,
body .p-datepicker table td > span.p-highlight {
  color: #ffffff;
  background-color: pvar(--mainColor);
}
body .p-datepicker table td > a {
  cursor: pointer;
}
body .p-datepicker table td > a:focus {
  outline: 0 none;
  outline-offset: 0;
  box-shadow: 0 0 0 0.2em pvar(--mainColorLightest);
}
body .p-datepicker table td.p-datepicker-today > a,
body .p-datepicker table td.p-datepicker-today > span {
  background-color: #d0d0d0;
  color: #333333;
}
body .p-datepicker table td.p-datepicker-today > a.p-highlight,
body .p-datepicker table td.p-datepicker-today > span.p-highlight {
  color: #ffffff;
  background-color: pvar(--mainColor);
}
body .p-datepicker table td.p-datepicker-weeknumber {
  border-right: 1px solid #a6a6a6;
}
body .p-datepicker .p-datepicker-buttonbar {
  border-top: 1px solid #d8dae2;
}
body .p-datepicker .p-timepicker {
  border: 0 none;
  border-top: 1px solid #d8dae2;
  padding: 0.857em;
}
body .p-datepicker .p-timepicker a {
  color: #333333;
  font-size: 1.286em;
}
body .p-datepicker .p-timepicker a:hover {
  color: pvar(--mainColor);
}
body .p-datepicker .p-timepicker span {
  font-size: 1.286em;
}
body .p-datepicker .p-monthpicker .p-monthpicker-month {
  color: #333333;
}
body .p-datepicker .p-monthpicker .p-monthpicker-month.p-highlight {
  color: #ffffff;
  background-color: pvar(--mainColor);
}
body .p-datepicker.p-datepicker-timeonly {
  padding: 0;
}
body .p-datepicker.p-datepicker-timeonly .p-timepicker {
  border-top: 0 none;
}
body .p-datepicker.p-datepicker-multiple-month .p-datepicker-group {
  @include padding-right(0.857em);
  @include padding-left(0.857em);

  border-right: 1px solid #d8dae2;
  padding-top: 0;
  padding-bottom: 0;
}
body .p-datepicker.p-datepicker-multiple-month .p-datepicker-group:first-child {
  @include padding-left(0);
}
body .p-datepicker.p-datepicker-multiple-month .p-datepicker-group:last-child {
  @include padding-right(0);
  border-right: 0 none;
}
body .p-calendar.p-calendar-w-btn .p-inputtext {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0 none;
}
body .p-calendar.p-calendar-w-btn .p-inputtext:enabled:hover:not(.p-error),
body .p-calendar.p-calendar-w-btn .p-inputtext:enabled:focus:not(.p-error) {
  border-right: 0 none;
}
body .p-calendar.p-calendar-w-btn .p-datepicker-trigger.p-button {
  width: 2.357em;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
body .ui-fluid .p-calendar.p-calendar-w-btn input.p-inputtext {
  width: calc(100% - 2.357em);
}
body p-calendar.ng-dirty.ng-invalid > .p-calendar > .p-inputtext {
  border: 1px solid #a80000;
}
body .p-timepicker .p-separator {
  @include margin-left(0);
  min-width: 0.75rem;
}

// auto complete
body .p-autocomplete .p-autocomplete-input {
  padding: 0.429em;
}
body .p-autocomplete-panel {
  padding: 0;
  border: 1px solid #c8c8c8;
  background-color: #ffffff;
  box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.16);
}
body .p-autocomplete-panel .p-autocomplete-items {
  padding: 0;
}
body .p-autocomplete-panel .p-autocomplete-items .p-autocomplete-item {
  margin: 0;
  padding: 0.429em 0.857em;
  border: 0 none;
  color: #333333;
  background-color: transparent;
  border-radius: 0;
}
body .p-autocomplete-panel .p-autocomplete-items .p-autocomplete-item.p-highlight,
body .p-autocomplete-panel .p-autocomplete-items .p-autocomplete-item:hover {
  color: #ffffff;
  background-color: pvar(--mainColor);
}
body .p-autocomplete-panel .p-autocomplete-items .p-autocomplete-group {
  padding: 0.429em 0.857em;
  background-color: #d8dae2;
  color: #333333;
}
body p-autocomplete.ng-dirty.ng-invalid > .p-autocomplete > .p-inputtext {
  border: 1px solid #a80000;
}

// ---------------------------------------------------------------------------
// PeerTube customizations
// ---------------------------------------------------------------------------

p-table {
  table {
    table-layout: fixed;
  }

  .p-datatable-header {
    border: none !important;
    background-color: pvar(--mainBackgroundColor) !important;

    .caption {
      min-height: 40px;
      width: 100%;
      display: inline-flex;
      align-items: center;

      .left-buttons {
        @include padding-left(15px);
      }
    }
  }

  th {
    background-color: pvar(--mainBackgroundColor) !important;
    outline: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  td, th {
    font-family: $main-fonts;
    font-size: 15px;
    color: pvar(--mainForegroundColor) !important;
  }

  td {
    @include padding-left(15px !important);

    &.expand-cell {
      padding: 10px 15px;
    }

    &:not(.action-cell):not(.expand-cell):not(.checkbox-cell) {
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      white-space: nowrap !important;
    }
  }

  tr {
    outline: 0;
    background-color: pvar(--mainBackgroundColor) !important;
    height: 46px;

    &.p-highlight {
      background-color: pvar(--submenuBackgroundColor) !important;

      td, td > a {
        color: pvar(--mainForegroundColor) !important;
      }
    }

    &.focus-visible {
      border: 1px solid pvar(--mainForegroundColor) !important
    }
  }

  .p-datatable-tbody {
    tr {
      &:hover {
        background-color: pvar(--submenuBackgroundColor) !important;
      }

      td {
        border: none !important;
        white-space: normal !important;
      }

      &:first-child td {
        border-top: none !important;
      }

      &:last-child td {
        border-bottom: none !important;
      }

      &:focus + tr > td,
      &:focus > td {
        box-shadow: none !important;
      }
    }

    .expander {
      cursor: pointer;
      position: relative;
      top: 1px;
    }
  }

  th {
    @include padding-left(15px);
    @include padding-right(0px);

    padding-top: 5px !important;
    padding-bottom: 5px !important;

    border: none !important;
    border-bottom: 1px solid !important;
    border-color: pvar(--submenuBackgroundColor) !important;
    text-align: start !important;
    font-weight: $font-semibold !important;
    color: pvar(--mainForegroundColor) !important;

    &.p-sortable-column:hover {
      background-color: pvar(--submenuBackgroundColor) !important;
    }

    &.p-sortable-column.focus-visible {
      border: 1px solid pvar(--mainForegroundColor) !important
    }

    &.p-highlight {
      background-color: pvar(--submenuBackgroundColor) !important;

      .pi-sort-amount-up-alt,
      .pi-sort-amount-down {
        display: inline-block;
        position: relative;
        top: -1px;
        color: pvar(--mainForegroundColor) !important;
      }

      .pi-sort-amount-up-alt {
        @include arrow-up(5px);
      }

      .pi-sort-amount-down {
        @include arrow-down(5px);
      }
    }
  }

  .action-cell {
    width: 250px !important;

    .dropdown-root,
    my-edit-button,
    my-delete-button,
    my-button {
      display: inline-block !important;
      @include margin-left(5px);

      &:first-child {
        @include margin-left(0)
      }
    }
  }

  p-paginator {
    .p-paginator {
      background-color: pvar(--mainBackgroundColor) !important;
      position: relative;
      border: none;
      border-top: 1px solid !important;
      border-color: pvar(--submenuBackgroundColor) !important;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;

      p-dropdown {
        .p-dropdown {
          @include padding-left(0.5rem);

          align-items: center;
        }

        &.p-focus {
          box-shadow: #{$focus-box-shadow-form} pvar(--mainColorLightest);
        }

        .p-label {
          color: pvar(--inputPlaceholderColor);
        }
      }

      .p-dropdown,
      .p-dropdown-trigger {
        color: pvar(--mainForegroundColor);
        background-color: pvar(--mainBackgroundColor);
      }

      .p-paginator-current {
        color: pvar(--inputPlaceholderColor);
        overflow: visible;
      }

      .p-paginator-first {
        margin-left: auto;
      }

      .p-paginator-last {
        margin-right: auto;
      }

      .p-paginator-first,
      .p-paginator-prev,
      .p-paginator-next,
      .p-paginator-last {
        padding: 5px 2px;
        height: 100%;
        outline: none;
        color: pvar(--mainForegroundColor);

        &.focus-within,
        &:focus {
          box-shadow: #{$focus-box-shadow-form} pvar(--mainColorLightest);
        }

        &.p-disabled:hover {
          background-color: #fff !important;
        }

        .p-paginator-icon {
          width: 18px;
          height: 18px;
        }

        &.p-paginator-prev {
          @include margin-right(10px);
        }

        &.p-paginator-next {
          @include margin-left(10px);
        }
      }

      .p-paginator-pages {
        height: auto !important;

        .p-paginator-page {
          &.focus-within,
          &:focus {
            box-shadow: #{$focus-box-shadow-form} pvar(--mainColorLightest) !important;
          }

          color: pvar(--mainForegroundColor) !important;
          font-weight: $font-semibold !important;
          margin: 0 5px !important;
          outline: 0 !important;
          border-radius: 3px !important;
          padding: 5px 2px !important;
          height: auto !important;
          line-height: initial !important;

          &.p-highlight {
            &, &:hover, &:active, &:focus {
              color: #fff !important;
              background-color: pvar(--mainColor) !important;
            }
          }
        }
      }
    }
  }

  .pt-badge {
    font-size: 12px;
    text-transform: uppercase;
  }
}

// overflow data table
p-table {
  .p-datatable-wrapper {
    overflow-x: auto;
    max-width: 100%;

    table {
      width: 100%;
    }
  }

  @media screen and (max-width: $small-view) {
    .p-datatable-wrapper {
      table {
        width: auto;
      }
    }

    p-paginator {
      .p-paginator-current {
        display: none !important;
      }
    }
  }

  @media screen and (max-width: $mobile-view) {
    p-paginator {
      .p-paginator-pages > .p-paginator-page:not(.p-highlight) {
        display: none;
      }
    }
  }
}

p-tablecheckbox:hover div .p-checkbox-box {
  box-shadow: 0 0 0 .1rem rgba(87, 85, 217, .2);
}

.p-checkbox {

  &, .p-checkbox-box {
    width: 18px !important;
    height: 18px !important;
  }

  .p-checkbox-box {
    &.p-highlight {
      color: pvar(--mainBackgroundColor) !important;
      background-color: pvar(--mainColor) !important;
      border-color: pvar(--mainColor) !important;
    }

    &.p-focus {
      border: 2px solid pvar(--mainForegroundColor) !important;
    }
  }
}

p-toast {
  .p-toast {
    width: auto;
    max-width: 300px;
    min-width: 200px;

    .p-toast-icon-close {
      opacity: 0;
      position: absolute;
      right: 5px;
      top: 5px;
      width: 18px;
      height: 18px;
      background: url('../assets/images/feather/x.svg') no-repeat;
      background-size: contain;
    }

    &:hover .p-toast-icon-close {
      opacity: .3;
    }
  }

  .p-toast-message {
    font-family: $main-fonts;
    background-color: pvar(--mainBackgroundColor) !important;
    color: pvar(--mainForegroundColor) !important;
    border-radius: 5px;
    box-sizing: border-box;
    border: 1px solid #EBEEF5 !important;
    box-shadow: 0 2px 12px 0 rgba(0, 0 , 0, .1);
    overflow: hidden;

    .notification-block {
      display: flex;
      align-items: center;
      width: 100%;
      padding: 10px 20px;

      .message {
        @include margin-right(20px);

        flex-grow: 1;

        h3 {
          font-size: 21px;
        }

        p {
          @include peertube-word-wrap;

          margin-bottom: 0;
        }
      }
    }
  }

  .p-toast-message-success my-global-icon {
    color: #8BC34A !important;
  }

  .p-toast-message-error my-global-icon {
    color: #F44336 !important;
  }

  .p-toast-message-warn my-global-icon {
    color: #F1680D !important;
  }

  .p-toast-message-info my-global-icon {
    color: #03A9F4 !important;
  }
}

@media screen and (max-width: $primeng-breakpoint) {
  p-table {
    td {
      padding: 3px 0;

      &.expand-cell {
        padding: 5px;
      }
    }

    .p-datatable-tbody {

      td:last-child {
        padding-bottom: 15px;
        margin-bottom: 15px;
        border-bottom: 1px solid $separator-border-color !important;
      }
    }
  }
}

@media screen and (max-width: $mobile-view) {
  p-table {
    .p-datatable-header {
      .caption {
        flex-wrap: wrap;

        > div {
          width: 100%;
          padding: 0 !important;
          margin-bottom: 5px;
        }
      }
    }
  }
}
