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

$params: (
   "border": global.$border-width solid global.$border-color,
   "border-radius": global.$border-radius-base,
   "margin-bottom": global.$gap-width,
   "padding": 10px 20px,
   "gap": global.$gap-width,
   "background": global.$white,

   "img-size": 50px,
   "img-mix-blend-enabled": 'false',
   "img-mix-blend-mode": darken,

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

   "product-name-color": global.$text-dark,
   "product-name-font-size": global.$font-size-base,
   "product-name-font-weight": global.$font-weight-base,
   "product-name-line-height": global.$line-height-sm,

   "price-color": global.$text-dark,
   "price-font-size": global.$font-size-base,
   "price-font-weight": global.$font-weight-bold,

   "decorative-enabled": 'false',
   "decorative-icon": 'gift',
   "decorative-color": darken(global.$white, 5%),
   "decorative-size": 58px,
   "decorative-position": auto auto -10px -10px,
);

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

   $params: map.merge($params, components.$c-product-gifts-gift);
}

.#{component("Product:Gifts:Gift", "class")} {
   container-type: inline-size;
   position: relative;
   overflow: hidden;
   width: 100%;
   border: map.get($params, "border");
   border-radius: map.get($params, "border-radius");
   margin-bottom: map.get($params, "margin-bottom");
   padding: map.get($params, "padding");
   background: map.get($params, "background");

   @if (map.get($params, "decorative-enabled") == true) {
      @supports (mask-image: none) {
         &::before {
            content: "";
            position: absolute;
            inset: map.get($params, "decorative-position");
            z-index: 0;
            width: 1em;
            height: 1em;
            background-color: map.get($params, "decorative-color");
            mask-image: unquote("url('/assets/icons/#{map.get($params, "decorative-icon")}.svg')");
            mask-size: 1em;
            mask-repeat: no-repeat;
            font-size: map.get($params, "decorative-size");
         }
      }
   }

   .inner-content {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: map.get($params, "gap");
   }

   .title {
      position: relative;
      flex: 100%;
      white-space: nowrap;
      color: map.get($params, "title-color");
      font-size: map.get($params, "title-font-size");
      font-weight: map.get($params, "title-font-weight");
   }

   .product {
      flex: 1;
      display: flex;
      align-items: center;
      gap: map.get($params, "gap");

      picture {
         max-width: 1em;
         min-width: .75em;
         background: map.get($params, "background");
         font-size: map.get($params, "img-size");
      }

      @if (map.get($params, "img-mix-blend-enabled") == true) {
         img {
            mix-blend-mode: map.get($params, "img-mix-blend-mode");
         }
      }
   }

   .product-name {
      white-space: normal;
      color: map.get($params, "product-name-color");
      font-size: map.get($params, "product-name-font-size");
      font-weight: map.get($params, "product-name-font-weight");
      line-height: map.get($params, "product-name-line-height");
   }

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

   .form-control-sm {
      max-width: 140px;
   }

   @container (inline-size > 360px) {
      @include global.container-query-selector(".inner-content") {
         flex-wrap: nowrap;
      }

      @include global.container-query-selector(".title") {
         flex: unset;
      }
   }
}
