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

$params: (
   "margin-bottom": global.$gap-width,
   "gap": global.$gap-width,

   "items-per-row": 4,
   "items-per-row-sm": 2,

   "image-overlay": "true",
   "image-width": 100%,
   "image-border": unset,
   "image-border-radius": global.$border-radius-base,
   "image-margin-bottom": global.$spacer,

   "flag-discount-position": absolute,
   "flag-discount-display": inline-block,
   "flag-discount-line-height": 1,
   "flag-discount-font-size": global.$font-size-smaller,
   "flag-discount-font-weight": global.$font-weight-bold,
   "flag-discount-color": global.$white,
   "flag-discount-background": global.$discount-color,
   "flag-discount-border-radius": global.$border-radius-base,
   "flag-discount-padding": 4px 8px,
   "flag-discount-left": 5px,
   "flag-discount-top": 5px,

   "title-font-size": global.$font-size-base,
   "title-font-weight": global.$font-weight-bold,
   "title-color": global.$text-dark,
   "title-margin": 0 10px 5px,
   "title-line-clamp":2,
   "title-line-height": global.$headings-line-height,
);

@if global-variable-exists(autocomplete-product-cell-item, components) {
   $keys: map.keys(components.$autocomplete-product-cell-item);
   @each $name in $keys {
      @if not map.get($params, $name) {
         @warn "Neexistující proměnná '#{$name}' v komponentě 'autocomplete-product-cell-item'.";
      }
   }

   $params: map.merge($params, components.$autocomplete-product-cell-item);
}

.autocomplete-product-cell-item {
   @include global.item-size(map.get($params, "items-per-row-sm"), map.get($params, "gap"));

   margin-bottom: map.get($params, "margin-bottom");

   &:last-child {
      margin-bottom: 0;
   }

   a {
      @include global.underline-never;
   }

   .img {
      @if (map.get($params, "image-overlay") == "true") {
         @include global.image-overlay;
      }

      position: relative;
      border: map.get($params, "image-border");
      border-radius: map.get($params, "image-border-radius");
      overflow: hidden;
      width: map.get($params, "image-width");
      margin-bottom: map.get($params, "image-margin-bottom");
   }

   .flag-discount {
      position: map.get($params, "flag-discount-position");
      top: map.get($params, "flag-discount-top");
      left: map.get($params, "flag-discount-left");
      display: map.get($params, "flag-discount-display");
      padding: map.get($params, "flag-discount-padding");
      color: map.get($params, "flag-discount-color");
      background: map.get($params, "flag-discount-background");
      border-radius: map.get($params, "flag-discount-border-radius");
      font-size: map.get($params, "flag-discount-font-size");
      font-weight: map.get($params, "flag-discount-font-weight");
      line-height: map.get($params, "flag-discount-line-height");
   }

   .title {
      font-size: map.get($params, "title-font-size");
      font-weight: map.get($params, "title-font-weight");
      color: map.get($params, "title-color");
      margin: map.get($params, "title-margin");
      line-height: map.get($params, "title-line-height");
      height: calc(map.get($params, "title-line-clamp") * map.get($params, "title-line-height") * map.get($params, "title-font-size"));
      overflow: hidden;
      -webkit-line-clamp: map.get($params, "title-line-clamp");
      display: -webkit-box;
      -webkit-box-orient: vertical;
   }

   @container (inline-size > 480px) {
      @include global.container-query-selector("&") {
         @include global.item-size(map.get($params, "items-per-row"), map.get($params, "gap"));
      }
   }
}
