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

$params: (
   "border": global.$border-width solid global.$border-color,

   "header-background-color": global.$black,
   "header-color": global.$white,
   "header-padding": 12px 15px,
   "header-items-gap": 8px,

   "header-title-color": global.$white,
   "header-title-font-size": global.$font-size-larger,
   "header-title-font-weight": global.$font-weight-base,

   "delete-color": global.$white,
   "delete-font-size": global.$font-size-larger,
   "delete-font-weight": global.$font-weight-base,

   "header-variations-background-color": global.$body-bg-alt,

   "empty-min-width": 436px,
   "empty-width": 100%,
   "empty-height": 60px,
   "empty-background-color": global.$white,

   "empty-total-width": 80px,
   "empty-total-background-color": global.$body-bg-alt,

   "variation-title-color": global.$text-dark,
   "variation-title-font-size": global.$font-size-smaller,
   "variation-title-font-weight": global.$font-weight-base,
   "variation-title-max-width": 80px,
   "variation-title-text-align": center,
   "variation-title-padding": 7px 0,
   "variation-title-flex": 0 0 80px,
   "variation-title-background-color": global.$body-bg-alt,


   "total-color": global.$text-dark,
   "total-font-size": global.$font-size-base,
   "total-font-weight": global.$font-weight-base,
   "total-width": 100%,
   "total-max-width": 80px,
   "total-height": 99px,
   "total-background-color": global.$body-bg-alt,
   "total-after-background": linear-gradient(270deg, global.$white, #fff0),
   "total-after-width": 40px,
);

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

   $params: map.merge($params, components.$c-productlist-tableview-group);
}

.#{component("ProductList:TableView:Group", "class")} {
   display: flex;
   flex-direction: column;
   width: 100%;

   .header-collection {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background-color: map.get($params, "header-background-color");
      color: map.get($params, "header-color");
      padding: map.get($params, "header-padding");

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

      .delete {
         display: flex;
         color: map.get($params, "delete-color");
         font-size: map.get($params, "delete-font-size");
         font-weight: map.get($params, "delete-font-weight");
         background: inherit;
         border: none;
         cursor: pointer;
      }
   }

   .header-collection-right {
      display: flex;
      align-items: center;
      gap: map.get($params, "header-items-gap");
   }

   .header-variations {
      display: flex;
      width: 100%;
      border-bottom: map.get($params, "border");
      background-color: map.get($params, "header-variations-background-color");

      .variation-title {
         color: map.get($params, "variation-title-color");
         font-size: map.get($params, "variation-title-font-size");
         font-weight: map.get($params, "variation-title-font-weight");
         max-width: map.get($params, "variation-title-max-width");
         flex: map.get($params, "variation-title-flex");
         text-align: map.get($params, "variation-title-text-align");
         border-right: map.get($params, "border");
         padding: map.get($params, "variation-title-padding");
         background-color: map.get($params, "variation-title-background-color");
         border-bottom: map.get($params, "border");
         margin-bottom: -1px;
         height: map.get($params,  "empty-height");
         display: flex;
         align-items: center;
         justify-content: center;

         &:first-child {
            border-left: map.get($params, "variation-title-border");
         }
      }
   }

   .table-item-wrapper {
      display: flex;
      flex-direction: column;
      justify-self: stretch;
   }

   .table-item-content {
      display: flex;

      .empty {
         min-width: map.get($params, "empty-min-width");
         background-color: map.get($params, "empty-background-color");
         height: map.get($params, "empty-height");
         border: map.get($params, "border");
      }

      &.no-variations {
         .empty, .header-variations, .empty-total {
            display: none;
         }

         .total {
            width: 80px;
         }
      }
   }

   .table-item-row {
      border: map.get($params, "border");
      border-top: unset;
      flex: 1;
   }

   .variations-wrapper-content {
      @include global.custom-scrollbar;

      display: flex;
      flex-direction: column;
      justify-content: stretch;
      width: 100%;
      position: relative;
      overflow-x: auto;
   }

   .has-scroll ~ .total-content::after {
      display: block;
   }

   .at-end {
      .header-variations {
         .variation-title:last-child {
            border-right: 0;
         }
      }

      .variations-items {
         .variations-wrapper:last-child {
            border-right: 0;
         }
      }
   }

   .total-content {
      display: flex;
      flex-direction: column;
      justify-content: stretch;
      max-width: map.get($params, "total-max-width");
      position: relative;

      &::after {
         display: none;
         background: map.get($params, "total-after-background");
         width: map.get($params, "total-after-width");
         bottom: 20px;
         content: "";
         position: absolute;
         left: -40px;
         top: 0;
      }

      .empty-total {
         width: map.get($params, "empty-total-width");
         height: map.get($params, "empty-height");
         background-color: map.get($params, "empty-total-background-color");
         border: map.get($params, "border");
      }

      .total {
         display: flex;
         flex-direction: column;
         align-items: center;
         justify-content: center;
         color: map.get($params, "total-color");
         font-size: map.get($params, "total-font-size");
         font-weight: map.get($params, "total-font-weight");
         border: map.get($params, "border");
         max-width: map.get($params, "total-max-width");
         width: map.get($params, "total-width");
         background-color: map.get($params, "total-background-color");
         border-bottom: map.get($params, "border");
         border-top: unset;
         flex: 1;

         span {
            display: flex;
            justify-content: center;
            align-items: center;
            width: map.get($params, "total-width");
            max-width: map.get($params, "total-max-width");
            height: map.get($params, "total-height");
         }
      }
   }
}
