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

$params: (
   "gap": global.$gap-width,
   "padding": 10px,

   "header-margin": 0 0 10px 0,

   "background": global.$body-bg,
   "background-hover": global.$body-bg,
   "background-active": global.$brand-primary,
   "background-soldout": global.$body-bg-alt,

   "border": global.$border-width solid global.$border-color,
   "border-hover": global.$border-width solid global.$brand-primary,
   "border-active": global.$border-width solid global.$brand-primary,
   "border-soldout": global.$border-width solid global.$body-bg-alt,

   "color": global.$text-dark,
   "color-hover": global.$text-dark,
   "color-active": global.$white,
   "color-soldout": global.$text-muted,

   "font-size": global.$font-size-larger,
   "font-size-large": global.$font-size-base,
   "font-weight": global.$font-weight-bold,
   "line-height": global.$line-height-tiny,
   "border-radius": global.$border-radius-base,

   "height": 40px,
   "height-large": 55px,

   "text-decoration-soldout": line-through,

);

@if global-variable-exists(c-product-variations-cellsmall, components) {
   $keys: map.keys(components.$c-product-variations-cellsmall);
   @each $name in $keys {
      @if not map.get($params, $name) {
         @warn "Neexistující proměnná '#{$name}' v komponentě '$#{component("Product:Variations:CellSmall", "class")}'.";
      }
   }

   $params: map.merge($params, components.$c-product-variations-cellsmall);
}

.#{component("Product:Variations:CellSmall", "class")} {
   width: 100%;
   container-type: inline-size;

   .variations-header {
      margin: map.get($params, "header-margin");
      color: map.get($params, "color");
   }

   > div {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: map.get($params, "gap");

      &.large {
         grid-template-columns: repeat(1, 1fr);

         label {
            height: map.get($params, "height-large");
            font-weight: global.$font-weight-base;
            font-size: map.get($params, "font-size-large");

            .title {
               font-weight: map.get($params, "font-weight");
            }
         }
      }
   }

   .cell-container {
      position: relative;
   }

   input {
      opacity: 0;
      position: absolute;
      z-index: -1;

      &:checked + label {
         color: map.get($params, "color-active");
         background: map.get($params, "background-active");
         border: map.get($params, "border-active");
      }
   }

   label {
      border: map.get($params, "border");
      color: map.get($params, "color");
      font-size: map.get($params, "font-size");
      font-weight: map.get($params, "font-weight");
      line-height: map.get($params, "line-height");
      border-radius: map.get($params, "border-radius");
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      height: map.get($params, "height");
      padding: map.get($params, "padding");
      position: relative;
      margin: 0;
      transition: all global.$transition-speed;
      text-align: center;

      &:hover {
         color: map.get($params, "color-hover");
         background: map.get($params, "background-hover");
         border: map.get($params, "border-hover");
      }
   }

   .soldout {
      color: map.get($params, "color-soldout");
      background: map.get($params, "background-soldout");
      border: map.get($params, "border-soldout");
      text-decoration: map.get($params, "text-decoration-soldout");
   }

   .c-icon {
      position: absolute;
      top: map.get($params, "icon-position-top");
      right: map.get($params, "icon-position-right");
      color: map.get($params, "icon-color");
      font-size: map.get($params, "icon-font-size");
   }

   @each $time, $color in map.get($params, "icon-color-by-delivery") {
      .delivery-#{$time} .c-icon {
         color: $color;
      }
   }

   @container (inline-size > 350px) {
      @include global.container-query-selector("> div:not(.large)") {
         grid-template-columns: repeat(4, 1fr);
      }
   }

   @container (inline-size > 400px) {
      @include global.container-query-selector("> div:not(.large)") {
         grid-template-columns: repeat(5, 1fr);
      }

      @include global.container-query-selector("> div.large") {
         grid-template-columns: repeat(2, 1fr);

         label {
            justify-content: flex-start;
            text-align: left;
         }
      }
   }

   @container (inline-size > 600px) {
      @include global.container-query-selector("> div:not(.large)") {
         grid-template-columns: repeat(7, 1fr);
      }
   }

   @container (inline-size > 800px) {
      @include global.container-query-selector("> div:not(.large)") {
         grid-template-columns: repeat(9, 1fr);
      }
   }
}
