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

$params: (
   "breakpoint-md": global.$md,
   "breakpoint-sm": global.$sm,

   "margin": 0 -10px,
   "margin-md": 0 -15px,

   "li-padding": 0 global.$spacer 0 0,
   "li-color": global.$text-muted,
   "li-font-size": global.$font-size-base,
   "li-line-height": 2,

   "title-padding": 0,
   "title-padding-resp": 10px 0,
   "title-margin": 0 0 10px,
   "title-margin-resp": 0,
   "title-background": none,
   "title-border": none,
   "title-color": global.$black,
   "title-font-size": global.$font-size-larger,
   "title-font-weight": global.$font-weight-base,
   "title-font-family": global.$font-family-base,
   "title-text-transform": normal,
   "title-align-items": stretch,
   "title-letter-spacing": normal,

   "column-border": global.$border-width solid global.$border-color,
   "column-padding": 5px 10px,
   "column-padding-md": 5px 15px,

   "icon-color": global.$black,
   "icon-font-size": global.$font-size-base,
);

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

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

.#{component("Footer:Menu", "class")} {
   display: flex;
   flex-wrap: wrap;
   flex-grow: 1;

   a {
      @include global.underline-hover;
   }

   .column {
      flex: 1 0 100%;

      @media screen and (min-width: map.get($params, "breakpoint-md")) {
         @for $i from 1 through 6 {
            &:first-child:nth-last-child(#{$i}),
            &:first-child:nth-last-child(#{$i}) ~ .column {
               flex-basis: (math.div(100, $i) - 3%);
               max-width: calc(percentage(math.div(100, $i)) - #{global.$gap-width});
            }
         }
      }
   }

   .title-default {
      padding: map.get($params, "title-padding");
      color: map.get($params, "title-color");
      background: map.get($params, "title-background");
      border: map.get($params, "title-border");
      font-size: map.get($params, "title-font-size");
      font-weight: map.get($params, "title-font-weight");
      font-family: map.get($params, "title-font-family");
      margin: map.get($params, "title-margin");
      pointer-events: none;
      text-transform: map.get($params, "title-text-transform");
      letter-spacing: map.get($params, "title-letter-spacing");

      .c-icon {
         display: none;
      }
   }

   li {
      padding: map.get($params, "li-padding");
      color: map.get($params, "li-color");
      font-size: map.get($params, "li-font-size");
      line-height: map.get($params, "li-line-height");

      &:last-child {
         padding-bottom: 0;
      }
   }

   @media screen and (max-width: map.get($params, "breakpoint-md") - 1) {
      flex-direction: column;
      margin: map.get($params, "margin-md");

      .column {
         flex-basis: unset;
         max-width: 100%;
         border-top: map.get($params, "column-border");
         padding: map.get($params, "column-padding-md");

         &:last-child {
            border-bottom: map.get($params, "column-border");
         }
      }

      .title-default {
         display: flex;
         width: 100%;
         justify-content: space-between;
         align-items: map.get($params, "title-align-items");
         padding: map.get($params, "title-padding-resp");
         margin: map.get($params, "title-margin-resp");
         cursor: pointer;
         pointer-events: all;

         .c-icon {
            display: block;
            color: map.get($params, "icon-color");
            font-size: map.get($params, "icon-font-size");
            transition: transform global.$transition-speed;
         }

         &.is-open {
            .c-icon {
               transform: rotate(-180deg);
            }
         }
      }

      ul {
         max-height: 0;
         overflow: hidden;
         transition: max-height global.$transition-speed ease;

         &.is-visible {
            max-height: 1000px;
         }
      }
   }

   @media screen and (max-width: map.get($params, "breakpoint-sm") - 1) {
      margin: map.get($params, "margin");

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