@use "base/color";
@use "base/colormode-light";
@use "base/colormode-dark";

@property --wy-color-scheme {
  syntax: "normal | light | dark";
  inherits: true;
  initial-value: normal;
}

@mixin color-mode($mode) {
  & :where(wy-chat),
  & :where(wy-comments),
  & :where(wy-component),
  & :where(wy-copilot),
  & :where(wy-feed),
  & :where(wy-file),
  & :where(wy-file-new),
  & :where(wy-files),
  & :where(wy-messenger-badge),
  & :where(wy-messenger-button),
  & :where(wy-messenger-conversation),
  & :where(wy-messenger-new),
  & :where(wy-messenger),
  & :where(wy-notification-badge),
  & :where(wy-notification-button),
  & :where(wy-notification-toasts),
  & :where(wy-notifications),
  & :where(wy-post-editor),
  & :where(wy-posts),
  :host(&),
  :host &,
  ::slotted(&) {
    @if ($mode == dark) {
      @include colormode-dark.styles();
      @include color.custom-properties-tokens(colormode-dark.$tokens);
    } @else {
      @include colormode-light.styles();
      @include color.custom-properties-tokens(colormode-light.$tokens);
    }
  }
}

:is(.wy-light, [part~="wy-light"]) {
  @include color-mode(light);
}

:is(.wy-dark, [part~="wy-dark"]) {
  &:not(.wy-light, [part~="wy-light"]) {
    @include color-mode(dark);
  }
}

// Note: Safari < 18.3.2 cannot use documentElement (html) as container, which causes a crash, so selector must be children of html
// See https://bugs.webkit.org/show_bug.cgi?id=271040
@container style(--wy-color-scheme: dark) {
  html :where(wy-chat),
  html :where(wy-comments),
  html :where(wy-component),
  html :where(wy-copilot),
  html :where(wy-feed),
  html :where(wy-file),
  html :where(wy-file-new),
  html :where(wy-files),
  html :where(wy-messenger-badge),
  html :where(wy-messenger-button),
  html :where(wy-messenger-conversation),
  html :where(wy-messenger-new),
  html :where(wy-messenger),
  html :where(wy-notification-badge),
  html :where(wy-notification-button),
  html :where(wy-notification-toasts),
  html :where(wy-notifications),
  html :where(wy-post-editor),
  html :where(wy-posts) {
      @include colormode-dark.styles();
      @include color.custom-properties-tokens(colormode-dark.$tokens);
  }
    
}
