@use "sass:meta";
@use "light";
@use "dark";
@use "subthemes";

// Available subthemes: ai, brand, brandSubtle, dimmed, dimmedSubtle, error, info, inverted, success
$available-subthemes: ("ai", "brand", "brandSubtle", "dimmed", "dimmedSubtle", "error", "info", "inverted", "success");

@mixin theming($dark-theme-selector: ".dark-theme", $subthemes: ()) {
  // Subtheme selectors
  @each $name in $available-subthemes {
    @if $subthemes == all or index($subthemes, $name) {
      [data-subtheme="#{$name}"] {
        @include meta.apply(meta.get-mixin("ds-subtheme-light-#{$name}", subthemes));
      }
      :global(#{$dark-theme-selector}) [data-subtheme="#{$name}"] {
        @include meta.apply(meta.get-mixin("ds-subtheme-dark-#{$name}", subthemes));
      }
    }
  }

  // Base theme + unset at the bottom (cascade order ensures unset overrides subthemes when nested)
  :root,
  [data-subtheme="unset"] {
    @include light.ds-theme-light;
  }

  :global(#{$dark-theme-selector}),
  :global(#{$dark-theme-selector}) [data-subtheme="unset"] {
    @include dark.ds-theme-dark;
  }
}
