@use "sass:map";
@use "sass:math";
@use "@twig/scss/_global" as global;
@use "@twig/scss/variables/_variables-components" as components;

$params: (
   "margin": 0 0 global.$spacer 0,

   "button-background-color": global.$white,
   "button-border-color": global.$border-color,
   "button-color": global.$text-dark,
   "button-background-color-active": global.$white,
   "button-border-color-active": global.$black,
   "button-color-active": global.$text-dark,

   "popup-title-color": global.$text-muted,
   "popup-title-font-size": global.$font-size-smaller,
   "popup-title-font-weight": global.$font-weight-base,
   "popup-title-margin-bottom": 0,

   "popup-left": -10px,
   "popup-top": calc(100% + 10px),
   "popup-width": 280px,
   "popup-padding": 20px,
   "popup-gap": global.$gap-width,
   "popup-background-color": global.$white,
   "popup-border": 1px solid global.$border-color,
   "popup-border-radius": global.$border-radius-base,
   "popup-box-shadow": global.$box-shadow,
   "popup-z-index": 2,

   "tooltip-icon-size": global.$font-size-smaller,
   "tooltip-icon-color": global.$text-dark,
);

@if global-variable-exists(c-section-filter-sorting-popup, components) {
   $keys: map.keys(components.$c-section-filter-sorting-popup);
   @each $name in $keys {
      @if not map.get($params, $name) {
         @warn "Neexistující proměnná '#{$name}' v komponentě '$#{component("Section:Filter:Sorting:Popup", "class")}'.";
      }
   }

   $params: map.merge($params, components.$c-section-filter-sorting-popup);
}

.#{component("Section:Filter:Sorting:Popup", "class")} {
   position: relative;
   margin: map.get($params, "margin");

   .btn-sort {
      background-color: global.$white;
      border-color: global.$border-color;
      color: global.$text-dark;

      @include global.haf {
         background-color: global.$white;
         border-color: global.$black;
         color: global.$text-dark;
      }
   }

   .sort-popup {
      display: none;
      flex-direction: column;
      position: absolute;
      left: map.get($params, "popup-left");
      top: map.get($params, "popup-top");
      width: map.get($params, "popup-width");
      padding: map.get($params, "popup-padding");
      gap: map.get($params, "popup-gap");
      background-color: map.get($params, "popup-background-color");
      border: map.get($params, "popup-border");
      border-radius: map.get($params, "popup-border-radius");
      box-shadow: map.get($params, "popup-box-shadow");
      z-index: map.get($params, "popup-z-index");

      &.active {
         display: flex;
      }

      p {
         color: map.get($params, "popup-title-color");
         font-size: map.get($params, "popup-title-font-size");
         font-weight: map.get($params, "popup-title-font-weight");
         margin-bottom: map.get($params, "popup-title-margin-bottom");
      }
   }

   .custom-control-input:checked ~ .custom-control-indicator {
      outline: 1px solid global.$custom-control-background-checked;
      border: 3px solid global.$body-bg;
   }

   .tooltip {
      position: relative;
      cursor: help;
      margin-left: 5px;

      .c-icon {
         color: map.get($params, "tooltip-icon-color");
         font-size: map.get($params, "tooltip-icon-size");
      }

      span {
         display: none;
         background: global.$body-bg;
         border: 1px solid  global.$border-color;
         color: global.$body-color;
         padding: 5px;
         font-size: global.$font-size-base;
         box-shadow: global.$box-shadow;
         position: absolute;
         text-align: center;
         z-index: 1000;
         white-space: normal;
         bottom: 100%;
         left: -10px;
         width: 250px;
      }

      @include global.haf {
         span {
            display: block;
         }
      }
   }
}
