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

$params: (
   "item-gap": 10px,
   "item-padding": global.$gap-width 0,
   "item-border-bottom": global.$border-width solid global.$border-color,

   "image-overlay": true,
   "image-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,

   "variation-font-size": global.$font-size-smaller,
   "variation-font-weight": global.$font-weight-base,
   "variation-color": global.$text-muted,

   "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-base,
   "delivery-font-weight": global.$font-weight-base,

   "delete-icon-size": 18px,
   "delete-icon-color": global.$text-dark,
   "delete-icon-color-hover": global.$state-error,
);

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

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

.#{component("ProductList:AccountItem", "class")} {
   display: flex;
   align-items: center;
   justify-content: space-between;
   flex: 1 0 100%;
   gap: map.get($params, "item-gap");
   padding: map.get($params, "item-padding");
   border-bottom: map.get($params, "item-border-bottom");
   container-type: inline-size;

   p {
      margin: 0;
   }

   > a {
      flex: 1;
      display: flex;
      align-items: center;
      gap: map.get($params, "item-gap");
      text-decoration: none;

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

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

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

      img {
         margin: auto;
      }
   }
   
   .content {
      flex: 1;
      display: flex;
      flex-direction: column;
   }

   .custom-info:has(*),
   .title-wrapper {
      flex: 1;
   }

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

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

   .#{component("Product:Price", "class")} {
      display: flex;
      align-items: baseline;
      margin: 0;

      > 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:Availability", "class")} {
      margin: 0;
      width: 120px;

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

   .delete-button {
      line-height: 1;
      width: 30px;
      text-align: right;

      a {
         font-size: map.get($params, "delete-icon-size");
         color: map.get($params, "delete-icon-color");
         transition: color global.$transition-speed;

         @include global.haf {
            color: map.get($params, "delete-icon-color-hover");
         }
      }
   }

   @container (inline-size > 700px) {
      @include global.container-query-selector(".content") {
         flex-direction: row;
         align-items: center;
         gap: map.get($params, "item-gap");
      }

      @include global.container-query-selector(".#{component("Product:Price", "class")}") {
         width: 20%;
         justify-content: flex-end;
      }
   }
}

