// Has dark mode adjustments, see dark-mode/misc.scss

// Map container

.openculturas-map {
  &[data-dirty=true] {
    .openculturas-map--reload {
      opacity: 1;
    }
  }
}

// Reload (results update) button on map

.openculturas-map--reload {
  @extend %button-small;
  @extend %oc-button--primary;
  @include icon(search);
  opacity: 0;
  transition: opacity 1s;
  translate: 0px -29.2rem;
  font-size: var(--font-size-s);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  margin: 0 auto;
  box-shadow: 0 0.5rem 1rem -0.5rem var(--color-text);

  &:before {
    margin-right: .5em;
  }
}

// Results list (teasers)

.openculturas-map--results {

  .map-link {
    white-space: nowrap;
    @include icon('map-marked');
    @extend %button-small;
    &::before {
      margin-right: 0.75rem;
    }
    article & {
      margin-top: 1rem;
    }
  }
}

.openculturas-map--results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: calc(var(--grid-gutter) * 2);
}


.openculturas-map:not([data-dirty=true]) {
  .openculturas-map--results-counter {
    // Loading indicator
    &[aria-busy=true] {
      &::after {
        content: '';
        z-index: 401;
        // Progress indicator thanks to
        // Vineeth.TR published unter MIT license on https://cssloaders.github.io/
        // todo: decide spinner type and put in mixin (use generic classes for broader use)
        height: 0.75rem;
        width: 0.75rem;
        margin-left: 0.75rem;
        border: 2px solid var(--color-info);
        border-bottom-color: transparent;
        border-radius: 50%;
        display: inline-block;
        box-sizing: border-box;
        animation: rotation 1s linear infinite;
      }

      @keyframes rotation {
        0% {
          transform: rotate(0deg);
        }
        100% {
          transform: rotate(360deg);
        }
      }
    }
  }
}

.openculturas-map--results-list > div {
  display: flex;
  flex-flow: column;
  gap: 0 var(--grid-gutter);
  align-items: center;
  justify-content: space-between;
  @include breakpoint(m) {
    flex-flow: row nowrap;
  }
}

.openculturas-map--container,
body .block-system-main-block > article.layout-wide.view-mode-full .attachment-before.openculturas-map--container {
  grid-column: 1/-1;
  min-height: 20rem;
  position: relative;
}

// OC adjustments to Leaflet defaults (interaction elements)

.openculturas-map--leaflet {
  min-height: 30rem;

  .leaflet-div-icon {
    background: none;
    border: none;
    position: relative;

    .custom-cluster-icon {
      position: relative;

      img {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        width: 100%;
      }

      span {
        position: absolute;
        width: 1.5rem;
        height: 1.5rem;
        line-height: 1.5rem;
        background-color: var(--color-map-marker);
        color: var(--color-text-inverted);
        text-align: center;
        border-radius: 1rem;
        margin-left: 0.0625rem;
      }
    }
  }

  .marker-located {
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 100%;
    background: var(--color-info);
    border: 1px solid var(--color-bg-light);
    outline: var(--outline-active);
  }

  .marker-cluster div {
    width: 1.875rem;
    height: 1.875rem;
    line-height: 1.875rem;
    margin-left: 0.3rem;
    margin-top: 0.3rem;
    text-align: center;
  }

  .marker-cluster-group-link {
    cursor: pointer;
  }

  // Marker popups

  .popup-grid {
    display: flex;
    gap: 1rem;
    justify-content: space-evenly;


    //@todo if possible, replace px with rem measures
    &:has(.image) {
      min-width: 300px;

      &:has(.popup-list) {
        min-width: 400px;
      }
    }

    .details {
      display: flex;
      flex-direction: column;
      flex: 1;
      p {
        margin: 0;
      }
    }

    .image {
      max-width: 38%;
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        border-radius: 100%;
        aspect-ratio: 1;
        object-fit: cover;
      }
    }
  }

  .leaflet-control-geocoder-icon {
    &:focus {
      background-color: var(--color-bg-light);
    }
  }

  .leaflet-control-geocoder-expanded {
    border: 1px solid var(--color-divider-dark);
    background: var(--color-bg-light);
    input {
      &:focus {
        border-bottom-color: transparent;
        box-shadow: none;
      }
    }
  }

  .leaflet-control-geocoder-alternatives {
    li {
      a {
        &:focus,
        &:hover {
        color: var( --color-interaction);
      }
      }
    }
  }

  .leaflet-popup-content ul {
    list-style: none;
    margin: 0;
    padding: 0;

    li {
      &:first-child {
        margin-top: 1rem;
      }
    }
  }

  .upcoming--more-link {
    margin-top: .5em;
  }

  // Search radius

  .leaflet-pane > svg path.leaflet-interactive {
    stroke: var(--color-info);
    fill: var(--color-info);
  }
}

.openculturas-map--container {
  position: relative;
  height: 30rem;
  overflow: visible;

  .openculturas-map--leaflet {
    height: 100%;
    width: 100%;
    isolation: isolate;
  }
}

// Results filter block, toggleable

.openculturas-map--overlay {
  position: absolute;
  top: 0;
  right: 0;
  margin: 0.6rem 0 0 0;
  padding: .25rem;
  width: 2.5rem;
  min-height: 4.5rem;
  transition: transform 300ms ease;
  z-index: +1;
  background: var(--color-bg-form);
  box-shadow: var(--box-shadow);
  @media (prefers-reduced-motion: reduce) {
    transition-duration: 10ms;
  }

  @include icon(sliders) {
    color: var(--color-interaction);
    position: absolute;
    padding: 0.5em;
    top: .25rem;
    right: .25em;
    font-size: 1rem;
  }

  & > summary {
    height: 4rem; // both icons clickable
    margin-bottom: -3rem; // ...but do not push form too far down
  }

  & > summary:before {
    transform: rotate(90deg);
    font-size: var(--font-size-default);
    float: none;
    position: absolute;
    right: 0;
    top: 1.75rem;
  }

  &[open] {
    width: 20rem;
    min-width: 20rem;
    max-width: 90%;
    padding: 0;

    &:has(.bef--secondary[open]) {
      width: auto;
    }

    @include breakpoint(m) {
      width: 27rem; // German buttons still side by side

      &:has(.bef--secondary[open]) {
        width: 53rem;
      }
    }

    & > summary:before {
      transform: rotate(-90deg);
      z-index: +1;
      top: 2rem; // adjust visual center
      right: .25rem; // adjust visual center
    }

  }
  details:last-of-type {
    margin-bottom: unset;
  }
}

.openculturas-map--filter-form {
  font-size: 1rem;

  form {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0 0.5rem;
    margin: .25rem 1.25rem;
    background: transparent; // parent element already has form bg
  }

  .bef--secondary {
    width: 100%;
    margin-bottom: 1rem;
  }

  .js-form-item-field-category-target-id,
  .js-form-item-field-sub-type-target-id {
    flex-basis: calc(50% - 0.5rem/2);
  }

  .form-item {
    flex-grow: 1;
    flex-shrink: 1;
  }

  select {
    width: 100%;
  }

  input[size='30'] {
    @include breakpoint(l) {
      max-width: unset;
    }
  }
  .ss-main {
    width: 100%;
  }

  div[class*="form-item-date"] {
    flex-basis: 10rem;
  }
}

// Leaflet popups generic

.leaflet-popup-close-button {
  @include icon(close);

  span {
    display: none;
  }

  .leaflet-container .leaflet-popup & {
    top: .5em;
    right: .5em;
  }
}

.leaflet-popup-content {
  margin: 1rem 3rem 1.5rem 1rem;

  .EventScheduled,
  .EventRescheduled {
    display: none;
  }

  .EventCancelled,
  .EventPostponed {
    color: var(--color-danger);
  }

  .EventMovedOnline {
    color: var(--color-text-muted);
  }

  span[class^="Event"] {
    padding-right: .5em;
  }

  time {
    padding-right: .25em
  }
}
