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

$params: (
   "item-background": global.$body-bg,
   "item-border": 0,
   "item-border-radius": global.$border-radius-base,
   "item-line-height": global.$line-height-sm,

   "labels-position": global.$spacer auto auto global.$spacer,

   "image-overlay": true,
   "image-border": 0,
   "image-border-radius": global.$border-radius-lg,
   "image-margin": 0 0 global.$spacer 0,

   "rating-position": auto global.$spacer global.$spacer auto,

   "content-padding": 0 10px,

   "title-font-size": global.$font-size-base,
   "title-font-weight": global.$font-weight-base,
   "title-color": global.$text-dark,
   "title-margin": 0 0 8px 0,
   "title-line-clamp": 2,

   "price-margin": 0,
   "price-font-size": 18px,
   "price-font-weight": global.$font-weight-bold,
   "original-price-color": global.$text-muted,
   "original-price-font-size": global.$font-size-smaller,

   "delivery-font-size": global.$font-size-smaller,
);

@if global-variable-exists(c-productlist-squareitemlarge, components) {
   $keys: map.keys(components.$c-productlist-squareitemlarge);
   @each $name in $keys {
      @if not map.get($params, $name) {
         @warn "Neexistující proměnná '#{$name}' v komponentě '$#{component("ProductList:SquareItemLarge", "class")}'.";
      }
   }

   $params: map.merge($params, components.$c-productlist-squareitemlarge);
}

.#{component("ProductList:SquareItemLarge", "class")} {
   position: relative;
   background: map.get($params, "item-background");
   border: map.get($params, "item-border");
   border-radius: map.get($params, "item-border-radius");
   line-height: map.get($params, "item-line-height");
   flex: 1 0 100%;

   .product-link {
      text-decoration: none;
   }

   .#{component("Product:Labels", "class")} {
      position: absolute;
      inset: map.get($params, "labels-position");
      z-index: 1;
   }

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

      border: map.get($params, "image-border");
      border-radius: map.get($params, "image-border-radius");
      overflow: hidden;
      margin: map.get($params, "image-margin");

      img {
         margin: auto;
      }
   }

   .#{component("Product:Reviews:Rating", "class")} {
      position: absolute;
      inset: map.get($params, "rating-position");
   }

   .content {
      padding: map.get($params, "content-padding");
   }

   .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");
      height: calc(map.get($params, "title-line-clamp") * map.get($params, "item-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;
   }

   .#{component("Product:Price", "class")} {
      display: flex;
      align-items: baseline;
      margin: map.get($params, "price-margin");

      > div {
         margin: 0 5px 0 0;

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

      p strong {
         color: map.get($params, "original-price-color");
         font-size: map.get($params, "original-price-font-size");
      }
   }

   .#{component("Product:DeliveryTime", "class")} {
      margin: 0;

      p {
         font-size: map.get($params, "delivery-font-size");
      }
   }

   .#{component("Product:SubmitBlock", "class")} {
      margin-top: global.$gap-width;

      .btn-ctr,
      .#{component("Product:AddToCartButton", "class")} {
         border-radius: global.$btn-border-radius;

         + .#{component("JsShop:ActionButton", "class")} {
            margin-left: 0;
            border-top-left-radius: global.$btn-border-radius;
            border-bottom-left-radius: global.$btn-border-radius;
         }
      }

      .#{component("JsShop:ActionButton", "class")} {
         + .#{component("JsShop:ActionButton", "class")} {
            margin-left: calc((#{global.$gap-width} + #{global.$btn-border-width}) * -1);
         }
      }
   }

   @container (inline-size > 800px) {
      @include global.container-query-selector("&") {
         @include global.item-size(2, global.$gap-width);
      }
   }
}

