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

$params: (
   "item-padding": 20px 15px,
   "item-gap-lg": 50px,
   "item-gap": global.$gap-width,
   "item-border-bottom": global.$border-width solid global.$border-color,

   "image-title-gap": 10px,
   "image-title-width": 250px,
   "image-overlay": true,
   "image-max-width": 74px,
   "image-border": 0,
   "image-border-radius": global.$border-radius-lg,

   "title-font-size": global.$font-size-base,
   "title-font-weight": global.$font-weight-base,
   "title-color": global.$text-dark,
   "title-margin": 0,

   "code-color": global.$gray,
   "code-font-size": global.$font-size-smaller,

   "labels-width": 150px,
   "labels-margin": 0,

   "delivery-width": 110px,
   "delivery-font-size": global.$font-size-smaller,
   "delivery-font-weight": global.$font-weight-base,

   "variation-padding": 15px,
   "variation-opener-icon-size": 18px,

   "price-width": 170px,
   "price-novat-font-size": global.$font-size-larger,
   "price-vat-font-size": global.$font-size-base,

   "button-max-width": 240px,
);

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

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

.#{component("ProductList:LineItemWithVariations", "class")} {
   border: map.get($params, "item-border-bottom");
   flex: 1 0 100%;
   container-type: inline-size;

   &.borderless {
      border: 0;
   }

   .product {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-direction: column;
      gap: map.get($params, "item-gap");
      padding: map.get($params, "item-padding");

      .content {
         justify-content: flex-end;

         > a {
            display: flex;
            align-items: center;
            gap: map.get($params, "image-title-gap");
            text-decoration: none;
            width: 100%;

            @include global.haf {
               .title {
                  text-decoration: underline;
               }
            }
         }
      }
   }

   .buy-form-wrapper {
      width: 100%;

      .btn-block {
         position: relative;

         .c-icon {
            position: absolute;
            right: 14px;
            top: 50%;
            transform: translateY(-50%);
            font-size: map.get($params, "variation-opener-icon-size");
            transition: global.$transition-speed;
         }

         &.active {
            .c-icon {
               transform: translateY(-50%) rotate(-180deg);
            }
         }
      }
   }

   .variations {
      border-top: 1px solid global.$border-color;
   }

   .variation {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-direction: column;
      padding: map.get($params, "variation-padding");
      gap: map.get($params, "item-gap");

      &:not(:last-child) {
         border-bottom: 1px solid global.$border-color;
      }

      .title-wrapper {
         max-width: fit-content;
         width: 100%;

         .code {
            margin-bottom: 0;
            color: map.get($params, "code-color");
            font-size: map.get($params, "code-font-size");
         }
      }
   }

   .content {
      flex: 1;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
   }

   .#{component("Product:Labels", "class")} {
      order: -1;
      width: 100%;
   }

   .labels-empty {
      display: none;
   }

   .#{component("Product:B2BPrice", "class")} {
      text-align: right;
      flex-direction: column;
      align-items: flex-end;
      width: 100%;

      .price-without-vat {
         font-size: map.get($params, "price-novat-font-size");
      }

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

   .#{component("Product:BuyForm", "class")} {
      display: flex;
      gap: 10px;
   }

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

      max-width: map.get($params, "image-max-width");
      width: 100%;
      border: map.get($params, "image-border");
      border-radius: map.get($params, "image-border-radius");
      overflow: hidden;

      img {
         margin: auto;
      }
   }

   .#{component("Product:DiscountLabel", "class")} {
      position: absolute;
      left: 10px;
      top: 10px;
   }

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

   .#{component("Product:DeliveryTime:Availability", "class")} {
      text-align: right;
      width: map.get($params, "delivery-width");
      margin: 0;

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

   @container (inline-size > 600px) {
      @include global.container-query-selector(".#{component("Product:B2BPrice", "class")}") {
         max-width: map.get($params, "price-width");
      }

      @include global.container-query-selector(".product .content") {
         justify-content: space-between;

         > a {
            width: map.get($params, "image-title-width");
         }
      }

      @include global.container-query-selector(".#{component("Product:DeliveryTime:Availability", "class")}") {
         text-align: center;
      }

      @include global.container-query-selector(".variation .title-wrapper") {
         max-width: calc(map.get($params, "image-title-width") - calc(map.get($params, "image-max-width") + map.get($params, "image-title-gap")));
      }
   }

   @container (inline-size > #{global.$md}) {
      @include global.container-query-selector(".labels-empty") {
         display: block;
      }

      @include global.container-query-selector(".variation .title-wrapper") {
         margin-left: calc(map.get($params, "image-max-width") + map.get($params, "image-title-gap"));
      }

      @include global.container-query-selector(".#{component("Product:DeliveryTime:Availability", "class")}") {
         text-align: left;
      }

      @include global.container-query-selector(".#{component("Product:Labels", "class")}") {
         order: 0;
      }

      @include global.container-query-selector(".#{component("Product:Labels", "class")}, .labels-empty") {
         width: map.get($params, "labels-width");
         margin: map.get($params, "labels-margin");
      }

      @include global.container-query-selector(".content") {
         flex-wrap: nowrap;
      }
   }

   @container (inline-size > #{global.$lg}) {
      @include global.container-query-selector(".product, .variation") {
         flex-direction: row;
         gap: map.get($params, "item-gap-lg");
      }

      @include global.container-query-selector(".buy-form-wrapper") {
         max-width: map.get($params, "button-max-width");
      }
   }
}
