@use "./base";
// Importing all the components
@use "./components/all-components-sparnatural-form.scss";
// we are importing one default theme,
// so that all the variables have a default value.
// they can be overriden by importing another theme CSS in the HTML page
@import "themes/sparnatural-theme-grass.css";

@media (prefers-color-scheme: light) {
  :root {
    --light: true;
  }
}

sparnatural-form {
  display: block;
  //padding: 20px;
  //padding: 2px;
  // This is the same color as background of Sparnatural with default theme "grass"
  background-color: #e8fcf5;
  border-radius: 5px;
  margin-bottom: 20px;
  padding-top: 15px;

  .sparnatural-form-container {
    max-height: 70vh; /* Limite en hauteur */
    overflow-y: auto; /* Permet de scroller */
    position: relative;
  }

  .sparnatural-form-container.scrollable + .submitSection::after {
    content: "";
    position: absolute;
    top: -20px; // Place l'ombre juste au-dessus de la section
    left: 0;
    right: 0;
    height: 20px; // Hauteur de l'ombre
    background: linear-gradient(to top, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
    pointer-events: none; // Empêche toute interaction
    z-index: -1; // Place l'ombre sous la section
  }

  /* Désactiver le gradient par défaut */
  .sparnatural-form-container + .submitSection::after {
    content: none;
  }

  .formField {
    padding-left: 20px;
    margin-bottom: 10px;
    padding-right: 10px;
  }

  // Display container for selected values
  .value-display-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
  }

  // Each selected value container
  .selected-value-container {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background-color: var(--primary-color-medium);
    border-radius: 5px;
    font-size: 13px;
    margin-bottom: 5px;
  }

  // Align selected values horizontally with wrapping
  .selected-value-container {
    flex-direction: row;

    padding: 5px;
    display: inline-block;
    margin-right: 10px;
    margin-bottom: 10px;
  }

  // Styling the selected value label
  .selected-value-label {
    margin-right: 10px;
    font-weight: normal;
    color: var(--default-text-color);
  }

  // Container for the search button to control its position
  .button-container {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
  }

  .submitSection {
    position: sticky; // Toujours visible
    bottom: 0; // Collée en bas
    z-index: 1000; // Toujours au-dessus
    justify-content: flex-end;
    display: flex;
    padding: 4px;
    background-color: #e8fcf5;
    height: max-content;
    gap: 10px;
    border-radius: 10%;

    .gui-split-button {
      display: inline-flex;
      border-radius: 6px;
      background: var(--secondary-color-important);
      color: #fff;
      fill: #fff;
      touch-action: manipulation;
      user-select: none;
      -webkit-tap-highlight-color: transparent;
    }

    .gui-split-button button {
      cursor: pointer;
      appearance: none;
      background: none;
      border: none;

      display: inline-flex;
      align-items: center;
      gap: 1ch;
      white-space: nowrap;

      font-family: inherit;
      font-size: inherit;
      font-weight: 500;

      padding-block: 1.25ch;
      padding-inline: 2.5ch;

      color: #fff;
      outline-color: #fff;
      outline-offset: -5px;

      border-right: 1px solid hsl(220, 50%, 85%); // Couleur claire pour contraster

      &:is(:hover, :focus-visible) {
        background: rgb(1, 109, 69);
        color: hsl(220 90% 98%);

        & > svg {
          stroke: currentColor;
          fill: none;
        }
      }

      &:active {
        background: rgb(1, 109, 69);
      }
    }

    .gui-split-button > button {
      border-end-start-radius: 6px;
      border-start-start-radius: 6px;

      & > svg {
        fill: none;
        stroke: #fff;
      }
    }

    .gui-popup-button {
      inline-size: 4ch;
      cursor: pointer;
      position: relative;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border-inline-start: 6px;
      border-start-end-radius: 6px;
      border-end-end-radius: 6px;

      &:is(:hover, :focus-within) {
        background: rgb(1, 109, 69);
      }

      &:focus {
        outline: none;
      }

      &:active {
        background: rgb(1, 109, 69);
      }

      &:focus-within {
        & > svg {
          transition-duration: 0.2s;
          transform: rotateZ(0.5turn);
        }
        & > .gui-popup {
          transition-duration: 0.2s;
          opacity: 1;
          transform: translateY(0);
          pointer-events: auto;
        }
      }
    }

    .gui-popup-button[aria-expanded="true"] .gui-popup {
      display: block; /* Show dropdown when expanded */
    }

    .gui-popup-button.disabled {
      pointer-events: none;
      cursor: not-allowed;
      background-color: #ccc;
      opacity: 0.5;
    }

    .gui-popup {
      opacity: 0;
      pointer-events: none; // Désactive l'interaction par défaut
      list-style: none;
      position: absolute;
      top: 100%; // Place le menu juste en dessous du bouton
      left: -90px;
      background-color: white;
      border: 1px solid #ddd;
      box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      z-index: 1000;
      padding: 0;
      margin: 0;
      transition: opacity 0.3s ease, transform 0.3s ease;
      transform: translateY(-10px); // Légèrement au-dessus initialement
    }

    .gui-popup:not(.hidden) {
      opacity: 1; // Rendre visible
      pointer-events: auto; // Activer l'interaction
      transform: translateY(0); // Réinitialiser la position
    }

    .gui-popup li button {
      //width: 100%;
      padding: 10px 20px;
      border: none;
      border-radius: 5px;
      background: none;
      text-align: left;
      cursor: pointer;
      color: #000;
    }

    .gui-popup li button:hover {
      background-color: rgb(1, 109, 69);
      color: #fff;
    }

    .gui-split-button svg {
      inline-size: 2ch;
      box-sizing: content-box;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-width: 2px;
    }

    button[id="Reset"] {
      padding: 10px 20px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      font-size: 14px;
      display: flex;
      align-items: center; /* Centrer verticalement le contenu */
      justify-content: center; /* Centrer horizontalement le contenu */
      text-align: center;
      position: relative; /* Nécessaire pour le spinner */
    }

    /*button[id="Search"] {
      background-color: var(--secondary-color-important);
      color: #000000;
      font-size: 15px;
      //border: 1px solid ;
      //box-shadow: 0px 2px 3px 0px #cfcfcf;
      transition: background-color 0.2s ease;
    }
    button[id="Search"]:hover {
      color: #fff;
      background-color: rgb(1, 109, 69);
    }
    
*/
    button[id="Search"]:disabled {
      background-color: #ccc; // Bouton gris lorsqu'il est désactivé
      color: #666;
      cursor: not-allowed;
    }

    button[id="Export"]:disabled {
      background-color: #ccc; // Bouton gris lorsqu'il est désactivé
      color: #666;
      cursor: not-allowed;
    }

    button[id="Reset"] {
      font-size: 15px;
      background-color: #fff;
      color: #000;
      //border: 1px solid #ddd;
      //box-shadow: 0px 2px 3px 0px #cfcfcf;
      transition: background-color 0.2s ease;
    }
    button[id="Reset"]:hover {
      background-color: #cacaca;
    }
  }

  /*.submitSection::after {
    content: "";
    position: absolute;
    top: -20px; // Place l'ombre juste au-dessus de la section
    left: 0;
    right: 0;
    height: 20px; // Hauteur de l'ombre
    background: linear-gradient(to top, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
    pointer-events: none; // Empêche toute interaction
    z-index: -1; // Place l'ombre sous la section
  }*/

  .option-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 10px;
  }

  .any-value-container,
  .not-exist-container {
    display: flex;
    flex-wrap: wrap;
    gap: px;
  }

  //style for the option pill for any value and not exist
  .option-pill {
    display: inline-flex;
    align-items: center;
    padding: 5px 3px;
    background-color: var(--primary-color-light, #ffcc99); /* Couleur ajustée */
    border-radius: 5px;
    font-size: 13px;
    color: var(--default-text-color, #333);
    border: 1px solid var(--primary-color-medium, #aaa);
    font-weight: normal;
  }

  .option-pill.any-value {
    background-color: #ffd699;
  }

  .option-pill.not-exist {
    background-color: #ffd699;
  }

  .option-pill .unselect {
    margin-left: 10px;
    cursor: pointer;
    border-radius: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    /*
    &:hover {
      background-color: var(--error-color, #d9534f);
    }*/
  }
  /* Spinner */
  .spinner {
    border: 4px solid #f3f3f3; /* Couleur de fond */
    border-radius: 50%;
    border-top: 4px solid #4caf50; /* Vert */
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-left: 10px;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }

  //ceci est pour le tree widget dans le formulaire
  .tree-widget {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    position: relative;
    gap: 10px;

    .treeBtnDisplay {
      position: relative;
      left: 0;
      top: auto;
      transform: none;
    }

    .treeLayer {
      top: 20px;
      left: 0;
      transform: none;

      .treeDisplay {
        max-height: 200px;
        min-width: none;
        max-width: 300px;
        padding: 25px 10px 5px;
      }
    }
  }
  .tree-close svg {
    z-index: 2000;
    position: relative;
  }

  //cette partie pour le loading spinner dans le formulaire
  .loadingspinner {
    display: none;
    left: 0;
  }

  .spinner {
    border: 3px solid #f3f3f3; /* Couleur de fond */
    border-top: 3px solid #4caf50; /* Vert */
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    display: inline-block;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
}
