@use "sass:map";
@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-alt,
   "background-active": global.$body-bg,

   "border": global.$border-width solid global.$border-color,
   "border-hover": global.$border-width solid global.$border-color,
   "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 20px,

   "data-font-size": global.$font-size-tiny,
   "data-color": global.$text-muted,

   "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),

   "item-line-height": global.$line-height-sm,
   "title-line-clamp": 2,

   "price-padding": 7px 0 0 0,
);

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

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

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

   .variations-header {
      margin-bottom: global.$gap-width;
   }

   > div:not(:first-child) {
      gap: map.get($params, "gap");
      display: flex;
      flex-direction: column;
   }

   .cell-container {
      position: relative;
   }

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

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

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

   label {
      display: flex;
      justify-content: space-between;
      align-items: stretch;
      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;

      > span:last-child {
         display: flex;
         flex-direction: column;
      }

      .data {
         display: block;
         white-space: nowrap;
         text-align: right;
         font-size: map.get($params, "data-font-size");
         color: map.get($params, "data-color");
      }

      .price {
         display: block;
         width: 100%;
         font-size: map.get($params, "font-size");
         font-weight: map.get($params, "font-weight");
         padding: map.get($params, "price-padding");
         margin-top: auto;
         text-align: right;
      }

      .title {
         display: block;
         color: map.get($params, "color");
         font-size: map.get($params, "font-size");
         font-weight: map.get($params, "font-weight");
         min-height: calc(map.get($params, "title-line-clamp") * map.get($params, "item-line-height") * map.get($params, "font-size"));
      }

      .#{component("Product:DeliveryTime", "class")} {
         pointer-events: none;
         margin: 0;
         padding: 0;
         border: 0;

         .delivery {
            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");

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

   button {
      @include global.btn-reset;
      @include global.underline-default;

      display: flex;
      align-items: center;
      padding: map.get($params, "toggle-padding");
      margin: map.get($params, "toggle-margin");
      font-size: map.get($params, "toggle-font-size");
      font-weight: map.get($params, "toggle-font-weight");
      color: map.get($params, "toggle-color");
      cursor: pointer;

      .c-icon {
         margin-right: map.get($params, "toggle-icon-margin-right");
         font-size: map.get($params, "toggle-icon-font-size");
         color: map.get($params, "toggle-icon-color");
         transition: transform global.$transition-speed;

         @if (map.get($params, "toggle-icon") == "false") {
            display: none;
         }
      }

      &.active {
         .c-icon {
            transform: map.get($params, "toggle-icon-active-transform");
         }
      }
   }

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

   @container (min-width: 500px) {
      @include global.container-query-selector("> div") {
         grid-template-columns: repeat(4, 1fr);
      }
   }
}
