// ArraySubs -> Webhooks modals: endpoint form, signing secret, event picker
// and the delivery detail with its attempt history. Modals render in a
// portal outside .arraysubs-admin-page.

.arraysubs-webhooks-modal {
  .button:has(> svg) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }
}

.arraysubs-webhooks-form {
  display: flex;
  flex-direction: column;
  gap: 18px;

  &--secret p {
    margin: 0;
  }

  &__field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;

    input[type="text"],
    input[type="url"] {
      width: 100%;
      max-width: 100%;
    }
  }

  &__label {
    color: #1d2327;
    font-size: 13px;
    font-weight: 600;
  }

  &__help {
    margin: 0;
    color: #646970;
    font-size: 12px;
    line-height: 1.5;
  }

  &__switch {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  &__switch-label {
    color: #1d2327;
    font-size: 13px;
    cursor: pointer;
  }
}

// Signing secret
.arraysubs-webhooks-secret {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid #dcdcde;
  border-radius: 6px;
  background: #f6f7f7;

  &__header {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  &__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  &__value {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    background: #fff;
    color: #1d2327;
    font-size: 12px;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  &__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
}

// Event picker
.arraysubs-webhooks-events {
  &__groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 4px;
  }

  &__group {
    min-width: 0;
    margin: 0;
    padding: 10px 12px 12px;
    border: 1px solid #dcdcde;
    border-radius: 6px;
    background: #fff;

    &--subscription {
      grid-column: 1 / -1;

      .arraysubs-webhooks-events__list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 24px;
      }
    }
  }

  &__legend {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 0;
    color: #1d2327;
    font-size: 13px;
    font-weight: 600;
  }

  &__select-all {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #50575e;
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;

    input {
      margin: 0;
    }
  }

  &__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0 0;
    padding: 0;
    list-style: none;

    > li {
      margin: 0;
    }
  }

  &__item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;

    input {
      flex-shrink: 0;
      margin: 2px 0 0;
    }
  }

  &__text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
  }

  &__label {
    color: #1d2327;
    font-size: 13px;
    line-height: 1.4;
  }

  &__description {
    color: #646970;
    font-size: 12px;
    line-height: 1.4;
  }

  &__key {
    width: fit-content;
    max-width: 100%;
    padding: 0 4px;
    background: transparent;
    color: #8c8f94;
    font-size: 11px;
    overflow-wrap: anywhere;
  }

  // Subscribed keys missing from the catalog (e.g. a custom event's plugin is off).
  &__unavailable {
    overflow-wrap: anywhere;

    &--removing {
      color: #6e3b00;
    }
  }
}

// Delivery detail
.arraysubs-webhooks-delivery {
  display: flex;
  flex-direction: column;
  gap: 16px;

  &__summary {
    display: grid;
    grid-template-columns: minmax(120px, 160px) minmax(0, 1fr);
    gap: 8px 16px;
    margin: 0;

    dt {
      color: #646970;
      font-weight: 600;
    }

    dd {
      min-width: 0;
      margin: 0;
      overflow-wrap: anywhere;
    }
  }

  &__status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  &__section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;

    h3 {
      margin: 0;
      color: #1d2327;
      font-size: 13px;
      font-weight: 600;
    }

    pre {
      overflow: auto;
      max-height: 280px;
      margin: 0;
      padding: 12px;
      border: 1px solid #dcdcde;
      border-radius: 4px;
      background: #f6f7f7;
      font-size: 12px;
      line-height: 1.5;
      white-space: pre-wrap;
      word-break: break-word;
    }
  }

  &__section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  &__loading {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  &__error {
    margin: 0;
    padding: 8px 12px;
    border-left: 4px solid #d63638;
    border-radius: 4px;
    background: #fcf0f1;
    color: #8a2424;
    overflow-wrap: anywhere;
  }
}

// Attempt history table in the delivery detail modal
.arraysubs-webhooks-attempts {
  th,
  td {
    vertical-align: top;
  }

  &__nowrap {
    white-space: nowrap;
  }

  &__error {
    min-width: 200px;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 782px) {
  .arraysubs-webhooks-events__groups {
    grid-template-columns: minmax(0, 1fr);
  }

  .arraysubs-webhooks-events__group--subscription .arraysubs-webhooks-events__list {
    grid-template-columns: minmax(0, 1fr);
  }

  .arraysubs-webhooks-delivery__summary {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;

    dd {
      margin-bottom: 8px;
    }
  }

  .arraysubs-webhooks-attempts {
    min-width: 560px;
  }
}

@media (max-width: 480px) {
  .arraysubs-webhooks-secret__actions {
    width: 100%;

    .button {
      flex: 1 1 auto;
      justify-content: center;
    }
  }
}
