@use "../base/var";
@use "../base/color";
@use "../base/text";

$embed-select-max-size: var.wy-rem(12);

[part~="wy-embed"] {
  display: flex;
  flex-direction: column;
  word-wrap: break-word;
  border-radius: var.default(--wy-border-radius-sm);
  clip-path: border-box;

  --wy-component-color: #{color.token(--wy-on-surface)};
  background-color: #{color.token(--wy-surface-layer)};
  color: var(--wy-component-color);
}

[part~="wy-embed-interactive"] {
  background-color: #{color.token(--wy-surface-layer)};

  user-select: none;
  cursor: pointer;

  // Hover state
  &:active,
  &:hover,
  &:focus {
    background-color: #{color.token(--wy-surface-layer-high)};
  }

  &[part~="wy-disabled"],
  &:disabled {
    pointer-events: none;

    // fix double border disabled (preview)
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-radius: 0;
    
    // fix border of parent being clipped
    background-color: transparent;
  }
}

[part~="wy-embed-area"] {
  display: flex;
  justify-content: center;
  align-items: center;
}

[part~="wy-embed-icon"] {
  width: var.wy-rem(3);
  height: var.wy-rem(3);
  flex: 0 0 auto;
  object-fit: contain;
}

/* iframed/embedded content */
[part~="wy-embed-content"] {
  display: flex;
  position: relative;
  padding: 0;
  overflow: hidden;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;

  iframe,
  embed,
  object,
  video {
    border: 0;
    width: auto;
    height: auto;
    max-height: var(--wy-component-max-size, #{var.default(--wy-embed-content-max-size)});
    //aspect-ratio: 4 / 3; // Set on each element
  }
}

// responsive image

[part~="wy-embed-photo"] {
  border-top-left-radius: var(--wy-component-border-top-radius, #{var.default(--wy-border-radius-sm)});
  border-top-right-radius: var(--wy-component-border-top-radius, #{var.default(--wy-border-radius-sm)});
  border-bottom-left-radius: var(--wy-component-border-bottom-radius, #{var.default(--wy-border-radius-sm)});
  border-bottom-right-radius: var(--wy-component-border-bottom-radius, #{var.default(--wy-border-radius-sm)});
  position: relative;
  background-size: cover;
  background-position: center;
  clip-path: border-box;

  &::after {
    border-top-left-radius: var(--wy-component-border-top-radius, #{var.default(--wy-border-radius-sm)});
    border-top-right-radius: var(--wy-component-border-top-radius, #{var.default(--wy-border-radius-sm)});
    border-bottom-left-radius: var(--wy-component-border-bottom-radius, #{var.default(--wy-border-radius-sm)});
    border-bottom-right-radius: var(--wy-component-border-bottom-radius, #{var.default(--wy-border-radius-sm)});
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 1;
    backdrop-filter: blur(32px);
    background-color: color.token(--wy-shade);
  }
}

[part~="wy-embed-photo-with-description"] {
  --wy-component-border-bottom-radius: 0;
}

// Placed in wy-embed-photo
[part~="wy-embed-image"] {
  //border-radius: var(--wy-component-border-radius);
  width: auto;
  height: auto;
  object-fit: contain;
  flex: 0 1 auto;
  min-width: 0;
  min-height: var.wy-rem(3);
  max-height: calc(var(--wy-component-max-size, #{var.default(--wy-embed-content-max-size)}) - #{var.default(--wy-padding)} * 2 - var.default(--wy-button-line-height) * var.default(--wy-size)); // --wy-embed-max-size - item-padding - item-row-min-size
  z-index: 2;
}

[part~="wy-embed-provider"] {
  color: color.token(--wy-outline);
  text-transform: uppercase;
  font-size: var.default(--wy-font-size-sm);
  margin-bottom: var.wy-rem(0.25);
  @include text.truncate;
}

// buttons for cycling through and removing embeds (only visible in editor)
[part~="wy-embed-actions"] {
  display: flex;
  justify-content: space-between;
}

// Override some styles when previewing the embed in editor????
[part~="wy-embed-select"] {
  display: flex;
  flex-direction: column;
  min-height: 0;
  --wy-component-max-size: #{$embed-select-max-size};
  --wy-component-background-color: transparent;
  
  // add som margins and borders in preview?
  wy-embed {
    //margin: var.wy-rem(.75);
    border: var.default(--wy-border) solid color.token(--wy-outline-variant);
    border-radius: var.default(--wy-border-radius);
    --wy-component-border-top-radius: 0;
    min-height: 0;

    display: none;
    &:first-of-type {
      display: block;
    }
  }
}
