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

$params: (
   "margin-bottom": global.$spacer-lg,
   "padding-bottom": 0,
   "border-bottom": none,

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

   "attach-name-gap": global.$spacer,
   "attach-name-color": global.$body-color,
   "attach-name-font-size": global.$font-size-base,
   "attach-name-font-weight": global.$font-weight-base,
   "attach-name-word-break": break-all,

   "attach-download-color": global.$body-color,
   "attach-download-font-size": global.$font-size-base,
   "attach-download-font-weight": global.$font-weight-base,
   "attach-download-text-transform": unset,

   "attach-icon-color": global.$black,
   "attach-font-size": global.$font-size-base,
   "attach-margin": 0 10px 0 0,

   "row-border-radius": global.$border-radius-base,

   "row-stripped-color": global.$body-bg-alt,
   "row-stripped-padding": 5px 10px,

   "row-border": global.$border-width solid global.$border-color,
   "row-bordered-padding": 5px 0,
);

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

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

.#{component("Product:Attachments", "class")} {
   container-type: inline-size;
   width: 100%;
   margin-bottom: map.get($params, "margin-bottom");
   padding-bottom: map.get($params, "padding-bottom");
   border-bottom: map.get($params, "border-bottom");

   .title-default {
      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");
   }

   table {
      width: 100%;

      tr {
         border-radius: map.get($params, "row-border-radius");
      }

      td {
         vertical-align: top;
      }

      td:first-child {
         padding-right: map.get($params, "attach-name-gap");
         color: map.get($params, "attach-name-color");
         font-size: map.get($params, "attach-name-font-size");
         font-weight: map.get($params, "attach-name-font-weight");
         border-radius: map.get($params, "row-border-radius") 0 0 map.get($params, "row-border-radius");
         word-break: map.get($params, "attach-name-word-break");
      }

      td:last-child {
         color: map.get($params, "attach-download-color");
         font-size: map.get($params, "attach-download-font-size");
         font-weight: map.get($params, "attach-download-font-weight");
         border-radius: 0 map.get($params, "row-border-radius") map.get($params, "row-border-radius") 0;
         text-transform: map.get($params, "attach-download-text-transform");

         .c-icon {
            color: map.get($params, "attach-icon-color");
            font-size: map.get($params, "attach-icon-font-size");
            margin: map.get($params, "attach-margin");
         }
      }

      a {
         display: flex;
         align-items: center;
         color: map.get($params, "attach-download-color");
      }
   }

   .table-stripped {
      tr:nth-child(odd) {
         background: map.get($params, "row-stripped-color");
      }

      td {
         padding: map.get($params, "row-stripped-padding");
      }
   }

   .table-bordered {
      border-top: map.get($params, "row-border");

      tr {
         border-bottom: map.get($params, "row-border");
      }

      td {
         padding: map.get($params, "row-bordered-padding");
      }
   }
}
