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

$params: (
   "gap": global.$gap-width,
   "background": global.$body-bg,
   "background-hover": global.$body-bg,
   "background-active": global.$body-bg,
   "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,
   "color": global.$text-dark,
   "color-hover": global.$text-dark,
   "color-active": global.$text-dark,
   "font-size": global.$font-size-base,
   "font-weight": global.$font-weight-bold,
   "delivery-font-size": global.$font-size-smaller,
   "delivery-font-weight": global.$font-weight-base,
   "border-radius": global.$border-radius-base,
   "padding": 10px 5px 10px calc(#{global.$custom-checkbox-size} + 30px),
   "toggle-padding": 5px,
   "toggle-margin": 12px auto,
   "toggle-font-size": global.$font-size-base,
   "toggle-font-weight": global.$font-weight-base,
   "toggle-color": global.$text-dark,
   "toggle-icon": "true",
   "toggle-icon-margin-right": 10px,
   "toggle-icon-font-size": global.$font-size-larger,
   "toggle-icon-color": global.$text-dark,
   "toggle-icon-active-transform": rotate(180deg),

   "checkbox-border-radius": global.$border-radius-sm,
   "checkbox-border-color-hover": global.$brand-primary,
   "checkbox-background-checked": global.$brand-primary,
   "checkbox-border-checked": global.$border-width solid global.$brand-primary,
   "checkbox-content-checked": global.$custom-checkbox-icon,
   "checkbox-font-size": global.$custom-checkbox-size,

   'responsive-breack-point': 355px,
   'responsive-breack-point-md': 775px,
);

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

   $params: map.merge($params, components.$c-product-variationlabel-cellcheckbox);
}

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

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

   .custom-control-indicator {
      left: 1rem;
      top: 50%;
      transform: translateY(-50%);
      border-radius: map.get($params, "checkbox-border-radius");
   }

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

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

         .custom-control-indicator {
            background: map.get($params, "checkbox-background-checked");
            border: map.get($params, "checkbox-border-checked");
            &::before {
               content: map.get($params, "checkbox-content-checked");
               font-size: map.get($params, "checkbox-font-size");
               position: absolute;
               left: 50%;
               top: 50%;
               transform: translate(-50%, -50%);
            }
         }

         .title {
            color: map.get($params, "color-active");
         }
      }
   }

   label {
      display: flex;
      flex-direction: column;
      justify-content: center;
      cursor: pointer;
      border: map.get($params, "border");
      border-radius: map.get($params, "border-radius");
      padding: map.get($params, "padding");
      line-height: global.$line-height-sm;
      position: relative;
      transition: all global.$transition-speed;
      margin: 0;

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

      .#{component("Product:DeliveryTime", "class")} {
         margin: 0;
         font-size: map.get($params, "delivery-font-size");
         font-weight: map.get($params, "delivery-font-weight");
      }

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

         .custom-control-indicator {
            border-color: map.get($params, "checkbox-border-color-hover");
         }

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

   @container (min-width: #{map.get($params, 'responsive-breack-point')}) {
      @include global.container-query-selector("> div") {
         grid-template-columns: repeat(2, 1fr);
      }
   }

   @container (min-width: #{map.get($params, 'responsive-breack-point-md')}) {
      @include global.container-query-selector("> div") {
         grid-template-columns: repeat(auto-fit, calc(25% - (#{map.get($params, "gap")} )));
      }
   }
}
