// 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.scss";

.pf-exp-node-panel {
  display: flex;
  flex-direction: column;
  height: 100%;

  &__header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding: 1rem;
  }

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

    .title {
      display: flex;
      align-items: center;
      gap: 0.5rem;

      h2 {
        font-weight: 600;
        font-size: 1rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--pf-color-text-muted);
        margin: 0;
      }
    }
  }

  article {
    padding: 1rem;
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    line-height: 1.5;

    p {
      margin: 0 0 0.75rem 0;
      line-height: 1.6;

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

    p code,
    li code {
      background-color: var(--pf-color-background);
      padding: 0.125rem 0.375rem;
      border-radius: 3px;
      font-size: 0.8125rem;
      border: 1px solid var(--pf-color-border);
    }

    strong {
      font-weight: 600;
    }

    hr {
      margin: 0;
      border: none;
      border-top: 1px solid var(--pf-color-border);
    }
  }

  &.collapsed {
    display: none;
  }

  i.pf-exp-node-panel__warning-icon--error {
    color: var(--pf-color-danger);
  }

  i.pf-exp-node-panel__warning-icon--warning {
    color: var(--pf-color-warning);
  }

  .pf-exp-node-panel__comment {
    border: 1px solid var(--pf-color-border);
    border-radius: 4px;
    background-color: var(--pf-color-background);
    resize: vertical;
    font-family: var(--pf-font);
    font-size: 0.875rem;
    padding: 0.75rem;
    width: 100%;
    min-height: 200px;
  }
}

.pf-exp-node-panel-sql-source {
  article {
    padding: 0;
    border: none;
  }

  .pf-sql-editor-container {
    height: 100%;
  }
}

.pf-exp-query-operations {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pf-exp-operations-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pf-exp-aggregations-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pf-exp-aggregation-editor {
  @extend .pf-exp-editor;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.pf-exp-aggregation-viewer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border-radius: 4px;
  gap: 0.5rem;

  &:hover {
    background-color: var(--pf-color-background-secondary);
  }

  span {
    cursor: pointer;
    flex-grow: 1;
  }

  .pf-button {
    flex-shrink: 0;
  }
}

// Structured modify view styling
.pf-exp-node-panel__modify {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

// Top buttons container - absolutely positioned overlay
.pf-exp-node-panel__buttons-top-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 10;

  .pf-button {
    pointer-events: auto;
  }
}

.pf-exp-node-panel__buttons-top {
  display: flex;
  justify-content: space-between;
  padding: 1rem 0;
  gap: 0.5rem;
}

// Bottom buttons - sticky at bottom of scrolling container
.pf-exp-node-panel__buttons-bottom {
  display: flex;
  justify-content: space-between;
  padding: 1rem 0.5rem 0.5rem 0;
  gap: 0.5rem;
  position: sticky;
  bottom: -0.5rem;
  margin-top: auto;
  z-index: 10;
  pointer-events: none;

  .pf-button {
    pointer-events: auto;
  }
}

.pf-exp-node-panel__buttons-top-left,
.pf-exp-node-panel__buttons-top-right,
.pf-exp-node-panel__buttons-bottom-left,
.pf-exp-node-panel__buttons-bottom-right {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pf-exp-node-panel__buttons-bottom-left,
.pf-exp-node-panel__buttons-bottom-right {
  .pf-button {
    pointer-events: auto;
    background-color: var(--pf-color-background);
  }
}

.pf-exp-node-panel__sections {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex-grow: 1;
}

.pf-exp-node-panel__section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 0;
  border-top: 1px solid var(--pf-color-border);

  &:first-child {
    border-top: none;
    padding-top: 0;
  }

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

.pf-exp-node-panel__section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--pf-color-text);
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  font-size: 0.75rem;
}

.pf-exp-node-panel__section-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  container-type: inline-size;
}
