// Copyright (C) 2025 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@import "../common";

.pf-exp-filters-header {
  display: flex;
  align-items: center;
  gap: 1rem;

  .pf-exp-filters-label {
    font-size: var(--pf-font-size-m);
    font-weight: 500;
    white-space: nowrap;
  }
}

// Filter chip wrapper for enabled/disabled state
.pf-filter-chip-wrapper {
  display: inline-flex;
  max-width: 100%;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;

  // Override chip's min-width to allow shrinking
  .pf-chip {
    min-width: 0;
    max-width: 100%;
  }

  &--disabled {
    opacity: 0.5;
    text-decoration: line-through;
  }

  &--compact {
    font-size: 11px;
  }
}

// Operator header for filter lists (AND/OR badge)
.pf-filter-operator-header {
  margin-bottom: 4px;
}

// Enabled count indicator
.pf-filter-enabled-count {
  font-size: 11px;
  color: var(--pf-color-text-muted);
  margin-bottom: 4px;
  margin-top: 4px;
}

// Filter chips container
.pf-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 250px;

  &--with-count {
    margin-top: 4px;
  }

  &--no-count {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;

    &.pf-filter-chips--compact {
      gap: 2px;
    }
  }

  &--compact {
    gap: 2px;
  }
}

// Filter summary for nodeDetails (simple text)
.pf-filter-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--pf-font-size-s);
  color: var(--pf-color-text-secondary);

  &__line {
    display: flex;
    align-items: baseline;
    gap: 2px;
  }
}

// Filter container base
.pf-filter-container {
  max-width: 250px;
  box-sizing: border-box;
  overflow: visible;
}

// AND filters header
.pf-filter-and-header {
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--pf-color-text-secondary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

// AND/OR operator badge
.pf-filter-operator-badge {
  background-color: var(--pf-color-background-secondary);
  color: var(--pf-color-text-muted);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: var(--pf-font-size-xs);
  font-weight: 500;
  text-transform: uppercase;

  &--small {
    padding: 1px 4px;
    font-size: 9px;
  }
}

// Grouped filter container
.pf-filter-container--grouped {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

// Individual filter group (one column)
.pf-filter-group {
  background-color: var(--pf-color-background-secondary);
  border-radius: 6px;
  padding: 6px 8px;

  &__header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
  }

  &__column {
    font-size: var(--pf-font-size-s);
    font-weight: 500;
    color: var(--pf-color-text-secondary);
  }
}

// AND connector between groups
.pf-filter-group-connector {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
}

// OR group container for nodeDetails and nodeSpecificModify
.pf-or-group-container {
  display: flex;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--pf-color-primary);
  border-radius: 8px;
  background-color: color-mix(in srgb, var(--pf-color-primary) 5%, transparent);
  margin-top: 8px;
  margin-bottom: 8px;

  &--disabled {
    opacity: 0.5;
  }
}

.pf-or-group-label {
  font-weight: bold;
  font-size: var(--pf-font-size-m);
  color: var(--pf-color-primary);
  min-width: 30px;
  display: flex;
  align-items: center;
}

.pf-or-group-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0; // Allow flexbox to shrink below content size
  overflow: hidden;

  &--compact {
    gap: 2px;
  }
}

.pf-or-group-controls {
  display: flex;
  align-items: center;
}

// Filters container with separator
.pf-filters-container {
  border-top: 1px solid var(--pf-color-border);
  padding-top: 12px;
  margin-top: 12px;
}

// Filter container with groups support
.pf-filter-container--with-groups {
  .pf-filter-chips {
    display: flex;
    flex-direction: column;
    gap: 4px;

    &--compact {
      gap: 2px;
    }
  }
}

// Query operations container spacing
.pf-exp-query-operations {
  margin-top: 16px;
}

// Filter mode help text
.pf-exp-filter-mode-help {
  margin-bottom: 16px;
  padding: 8px 12px;
  background-color: color-mix(in srgb, var(--pf-color-primary) 8%, transparent);
  border-left: 3px solid var(--pf-color-primary);
  border-radius: 4px;
  font-size: 13px;
  color: var(--pf-color-text);
  line-height: 1.4;
}

// Filter node content container
.pf-filter-node-content {
  display: flex;
  flex-direction: column;
  width: 100%;
}

// Filter input options (Create filter button + text input)
.pf-filter-input-options {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 8px 0;
}

// Separator between filter options
.pf-filter-or-separator {
  color: var(--md-sys-color-outline);
  font-size: var(--pf-font-size-m);
  font-weight: 500;
  flex-shrink: 0;
}

// Type filter text input container
.pf-filter-type-input {
  justify-self: end;
  width: 100%;
  max-width: 280px;

  // Make the text input fill the container
  .pf-text-input {
    width: 100%;
  }
}

// Filter list container
.pf-filters-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

// Disabled filter styling
.pf-filter-disabled {
  opacity: 0.5;
}

// Filter footer with operator toggle and mode switch
.pf-filter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

// SQL expression modal editor container
.pf-filter-sql-editor {
  min-height: 300px;
  // Matches the One Dark theme used by the CodeMirror editor
  background-color: var(--pf-editor-background, #282c34);
  position: relative;
}
