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

$params: (
   "breakpoint-md": global.$md,
   
   "margin": 0 0 40px 0,

   "header-align": center,

   "username-margin": 0,
   "username-color": global.$text-muted,
   "username-font-size": global.$font-size-base,
   "username-font-weight": global.$font-weight-base,
   "username-text-transform": none,
   "username-letter-spacing": normal,
   "username-line-height": inherit,

   "title-margin": 0,
   "title-color": global.$headings-color,
   "title-font-size": global.$font-size-h2,
   "title-font-weight": global.$font-weight-bold,
   "title-text-transform": none,
   "title-letter-spacing": normal,

   "subtitle-margin": 0,
   "subtitle-color": global.$text-muted,
   "subtitle-font-size": global.$font-size-base,
   "subtitle-font-weight": global.$font-weight-base,

   "gap": global.$gap-width,

   "item-flex-basis-resp": 45%,
   "item-flex-basis": 21%,
   "item-border-radius": global.$border-radius-lg,
   "item-background": global.$body-bg-dark,

   "icon-bottom": 10px,
   "icon-right": 10px,
   "icon-color": global.$white,
   "icon-size": 20px,

   "social-icons-margin": 20px 0 30px,
);

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

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

.#{component("Instagram", "class")} {
   container-type: inline-size;
   overflow: hidden;
   margin: map.get($params, "margin");

   .header {
      display: flex;
      flex-direction: column;
      align-items: map.get($params, "header-align");
   }

   .username {
      margin: map.get($params, "username-margin");
      color: map.get($params, "username-color");
      font-size: map.get($params, "username-font-size");
      font-weight: map.get($params, "username-font-weight");
      text-transform: map.get($params, "username-text-transform");
      letter-spacing: map.get($params, "username-letter-spacing");
      line-height: map.get($params, "username-line-height");
   }

   .title {
      margin: map.get($params, "title-margin");
      color: map.get($params, "title-color");
      font-size: map.get($params, "title-font-size");
      font-weight: map.get($params, "title-font-weight");
      text-transform: map.get($params, "title-text-transform");
      letter-spacing: map.get($params, "title-letter-spacing");
   }

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

   .#{component("SocialIcons", "class")} {
      margin: map.get($params, "social-icons-margin");
   }

   .instafeed {
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      gap: map.get($params, "gap");
   }

   .instafeed-item {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      flex: 1 0 map.get($params, "item-flex-basis-resp");
      aspect-ratio: 4 / 5;
      border-radius: map.get($params, "item-border-radius");
      overflow: hidden;
      background: map.get($params, "item-background");

      @include global.haf {
         img {
            opacity: .7;
         }
      }

      img {
         width: 100%;
         height: 100%;
         object-fit: cover;
         transition: opacity global.$transition-speed;
      }

      .c-icon {
         position: absolute;
         bottom: map.get($params, "icon-bottom");
         right: map.get($params, "icon-right");
         color: map.get($params, "icon-color");
         font-size: map.get($params, "icon-size");
      }
   }

   @container (inline-size > #{map.get($params, "breakpoint-md")}) {
      @include global.container-query-selector('.instafeed-item') {
         flex-basis: map.get($params, "item-flex-basis");
      }
   }
}
