@use "../../admin-ui" as ui;

/**
 * Profile Fields Settings Page
 *
 * @package ArraySubs
 */

// Card wrapper
.arraysubs-card {
  @include ui.card;
  padding: 24px;
  margin-bottom: 20px;

  &__title {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
  }

  &__description {
    color: #646970;
    margin: 0 0 20px;
  }
}

// Both profile editors share cards, native controls and the save bar.
.arraysubs-pf-layout,
.arraysubs-mae-layout {
  @include ui.controls;

  + .arraysubs-settings-actions {
    @include ui.controls;

    .arraysubs-bottom-fixed-actions__content {
      @include ui.card;
    }
  }
}

.arraysubs-pf-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: stretch;
  gap: 20px;
  margin-bottom: 20px;

  > .arraysubs-card,
  > .arraysubs-pf-sidebar {
    min-width: 0;
    margin-bottom: 0;
  }

  @media (max-width: 960px) {
    grid-template-columns: minmax(0, 1fr);
  }
}

.arraysubs-pf-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;

  > .arraysubs-card {
    margin-bottom: 0;

    &:last-child {
      flex: 1;
    }
  }
}

// Field editor
.arraysubs-field-editor {
  @include ui.card($radius: var(--arraysubs-radius-md));
  margin-bottom: 8px;
  transition: border-color 0.15s ease;

  &:hover {
    border-color: #8c8f94;
  }

  &--disabled {
    opacity: 0.6;
  }

  &--dragging {
    opacity: 0.5;
    border-color: var(--wp-admin-theme-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  }

  &--invalid {
    border-color: #d63638;
  }

  &__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
  }

  &__drag {
    color: #c3c4c7;
    cursor: grab;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 2px;
    border: none;
    background: none;
    border-radius: var(--arraysubs-radius-sm);
    touch-action: none;

    &:hover {
      color: var(--wp-admin-theme-color);
      background: #f0f0f1;
    }

    &:active {
      cursor: grabbing;
    }
  }

  &__label {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    font-weight: 500;
  }

  &__type-badge {
    font-size: 11px;
    background: #f0f0f1;
    color: #646970;
    border-radius: var(--arraysubs-radius-md);
    padding: 2px 8px;
    flex-shrink: 0;
  }

  &__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }

  &__toggle-btn,
  &__expand-btn,
  &__remove-btn {
    padding: 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: #646970;
    display: flex;
    align-items: center;
    border-radius: var(--arraysubs-radius-sm);

    &:hover {
      color: var(--wp-admin-theme-color);
      background: #f0f0f1;
    }

    &:disabled {
      opacity: 0.3;
      cursor: not-allowed;

      &:hover {
        color: #646970;
        background: none;
      }
    }
  }

  &__remove-btn:hover {
    color: #d63638;
  }

  // Expanded body
  &__body {
    border-top: 1px solid var(--arraysubs-card-border-color);
    padding: 16px;
  }

  &__row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;

    &:last-child {
      margin-bottom: 0;
    }
  }

  &__col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;

    label {
      font-weight: 500;
      font-size: 13px;
    }

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

    &--checkbox {
      flex-direction: row;
      align-items: center;
      padding-top: 22px;

      label {
        display: flex;
        align-items: center;
        gap: 6px;
        font-weight: 400;
      }
    }
  }

  &__hint {
    font-size: 12px;
    color: #8c8f94;
    font-style: italic;
  }

  &__error {
    font-size: 12px;
    color: #d63638;
    font-weight: 500;
  }

  &__warning {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    font-size: 12px;
    color: #8a6116;
    line-height: 1.4;

    svg {
      flex: 0 0 auto;
      margin-top: 2px;
    }
  }

  &__input--error {
    border-color: #d63638 !important;
    box-shadow: 0 0 0 1px #d63638;
  }

  // Select options editor
  &__options {
    margin-top: 4px;

    > label,
    > .arraysubs-field-editor__group-label {
      display: block;
      font-weight: 500;
      font-size: 13px;
      margin-bottom: 8px;
    }
  }

  &__option-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;

    > input[type="text"],
    > .arraysubs-tf-wrap {
      box-sizing: border-box;
      flex: 1;
      min-width: 0;
    }
  }

  &__option-remove {
    flex-shrink: 0;
    padding: 4px 6px !important;
    display: flex !important;
    align-items: center;
  }
}

// Avatar settings
.arraysubs-pf-avatar-settings {
  &__toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 20px;

    input[type="checkbox"] {
      flex: 0 0 auto;
      margin: 0;
    }
  }

  &__options {
    margin-top: 16px;
    padding-left: 26px;
  }

  &__row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;

    label {
      font-weight: 500;
      font-size: 13px;
    }

    input[type="number"] {
      width: 80px;
    }

    .regular-text {
      width: 100%;
      max-width: 400px;
    }
  }
}

// Fields list
.arraysubs-pf-fields-list {
  margin-bottom: 16px;
}

// Empty state
.arraysubs-pf-empty {
  padding: 24px;
  text-align: center;
  color: #646970;
  background: #f6f7f7;
  border: 1px dashed var(--arraysubs-card-border-color);
  border-radius: var(--arraysubs-radius-md);
  margin-bottom: 16px;

  p {
    margin: 0;
  }
}

// Add field button
.arraysubs-pf-add-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
}

// Responsive
@media (max-width: 782px) {
  .arraysubs-field-editor {
    &__row {
      flex-direction: column;
      gap: 12px;
    }

    &__col--checkbox {
      padding-top: 0;
    }

    &__header {
      flex-wrap: wrap;
    }

    &__actions {
      width: 100%;
      justify-content: flex-end;
    }
  }
}
