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

$params: (
   "justify-items": center,
   "align-items": center,
   "margin": 0 0 25px,

   "image-min-height-resp": 180px,
   "image-min-height": 250px,
   "image-border-radius": global.$border-radius-base,

   "inner-padding": 20px,

   "container-size": "true",
   "container-max-width": "false",

   "image-container-size": "true",
   "image-container-max-width": "false",

   "title-max-width": 100%,
   "title-margin": 0,
   "title-color": global.$headings-color,
   "title-font-size": global.$font-size-h2,
   "title-font-size-resp": global.$font-size-h2-sm,
   "title-font-weight": global.$font-weight-bold,
   "title-text-align": center,
   "title-text-transform": none,

   "image-title-color": global.$white,
   "image-title-text-align": center,

   "description-max-width": 600px,

   "image-description-max-width": 600px,
   "image-description-color": global.$white,
   "image-description-text-align": center,

   "resp-breakpoint": global.$sm,
);

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

   $params: map.merge($params, components.$c-section-imagetitle);
}

.#{component("Section:ImageTitle", "class")} {
   container-type: inline-size;
   position: relative;
   margin: map.get($params, "margin");

   &.has-image {
      display: grid;
      justify-items: map.get($params, "justify-items");
      align-items: map.get($params, "align-items");

      .#{component("Picture", "class")} {
         grid-area: 1 / 1;
         width: 100%;

         img {
            min-height: map.get($params, "image-min-height-resp");
            width: 100%;
            object-fit: cover;
            border-radius: map.get($params, "image-border-radius");
      
            @container (inline-size > #{map.get($params, "resp-breakpoint")}) {
               min-height: map.get($params, "image-min-height");
            }
         }
      }

      .inner-wrapper {
         grid-area: 1 / 1;
      }

      > .container {
         @if (map.get($params, "image-container-size") == "false") {
            max-width: global.$unset-max;
         } @else if (map.get($params, "image-container-max-width" ) != "false") {
            max-width: map.get($params, "image-container-max-width");
         }
      }

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

      h1 {
         color: map.get($params, "image-title-color");
         text-align: map.get($params, "image-title-text-align");
      }

      .#{component("Section:Description", "class")} {
         max-width: map.get($params, "image-description-max-width");
         color: map.get($params, "image-description-color");
         text-align: map.get($params, "image-description-text-align");
      }
   }

   h1 {
      max-width: map.get($params, "title-max-width");
      margin: map.get($params, "title-margin");
      color: map.get($params, "title-color");
      font-size: map.get($params, "title-font-size-resp");
      font-weight: map.get($params, "title-font-weight");
      text-align: map.get($params, "title-text-align");
      text-transform: map.get($params, "title-text-transform");

      @container (inline-size > #{map.get($params, "resp-breakpoint")}) {
         font-size: map.get($params, "title-font-size");
      }
   }

   > .container {
      @if (map.get($params, "container-size") == "false") {
         max-width: global.$unset-max;
      } @else if (map.get($params, "container-max-width" ) != "false") {
         max-width: map.get($params, "container-max-width");
      }
   }

   .#{component("Section:Description", "class")} {
      max-width: map.get($params, "description-max-width");
      margin-bottom: 0;
   }
}
