@use '../bubble-mixins' as bubble;

.image-message {
  @include bubble.bubble-media();
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 2px;
  transition: all 0.3s ease-in-out;
  min-height: 50px;
  max-width: 100%;

  &--loading {
    background-color: #f0f0f0;
  }

  &--error {
    background-color: #fff0f0;
  }

  &--loaded {
    background-color: transparent;
  }
}

.image-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(
      90deg,
      rgba(245, 245, 245, 100%) 0%,
      rgba(235, 235, 235, 100%) 50%,
      rgba(245, 245, 245, 100%) 100%
    );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.image-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 16px;
  min-height: 50px;

  &__icon {
    width: 32px;
    height: 32px;
    margin-bottom: 8px;
    background-color: #fdd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;

    &::before,
    &::after {
      content: "";
      position: absolute;
      width: 16px;
      height: 2px;
      background-color: #ff6b6b;
      transform: rotate(45deg);
    }

    &::after {
      transform: rotate(-45deg);
    }
  }

  &__text {
    font-size: 12px;
    color: #ff6b6b;
  }
}

.image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  min-height: 50px;

  &--visible {
    opacity: 1;
  }
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.image-preview__mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 1;
}

.image-preview__close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  z-index: 3;
}

.image-preview__close::before,
.image-preview__close::after {
  content: "";
  position: absolute;
  top: 15px;
  left: 8px;
  width: 16px;
  height: 2px;
  background: #fff;
}

.image-preview__close::before {
  transform: rotate(45deg);
}

.image-preview__close::after {
  transform: rotate(-45deg);
}

.image-preview__content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
  z-index: 2;
  pointer-events: none;
}

.image-preview__inner {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.image-preview__viewport {
  position: relative;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  pointer-events: none;
  overflow: visible;
}

.image-preview__img-wrap {
  position: relative;
  max-width: 100vw;
  max-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  border-radius: 0;
  background: transparent;
  pointer-events: auto;
}

.image-preview__img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  user-select: none;
  transition: transform 0.1s ease-out;
  pointer-events: auto;
}

.image-preview__img-wrap--error {
  background: rgba(255, 255, 255, 0.06);
}

.image-preview__error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  color: #fff;
  font-size: 14px;
}

.image-preview__error-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  position: relative;
}

.image-preview__error-icon::before,
.image-preview__error-icon::after {
  content: "";
  position: absolute;
  top: 22px;
  left: 14px;
  width: 20px;
  height: 2px;
  background: #fff;
}

.image-preview__error-icon::before { transform: rotate(45deg); }
.image-preview__error-icon::after { transform: rotate(-45deg); }

.image-preview__error-text {
  color: #fff;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}
