@use "sass:list";
@use "sass:meta";
@use "sass:map";

@use "./variants" as *;
@use "./accents" as *;
@use "./palette" as *;
@use "./theme" as *;

@use "../mixins" as *;
@use "../utils" as *;

// @in:
//   # Default accents colors: accent, warning, error, succes
//   $override-accents-preset: ThemePreset | null
//   # Custom colors preset, without mapping in palette context
//   $override-colors-preset: ThemePreset | null
//   # This option override global palette,
//   # all adittional color will compile with default mapper & convention
//   $override-palette: Palette | null
//   # Custom overrides color mappers & default appearance variables
//   $accents-context: AccentsContextMeta | null
// @out: builded css variables for all themes & components
// prettier-ignore
@mixin setup-theme(
  $override-accents-preset: (),
  $override-colors-preset: (),
  $override-palette: (),
  $accents-context: (),
) {
  $override-accents-preset: if($override-accents-preset != null, $override-accents-preset, ());
  $override-colors-preset: if($override-colors-preset != null, $override-colors-preset, ());
  $override-palette: if($override-palette != null, $override-palette, ());
  $accents-context: if($accents-context != null, $accents-context, ());

  // Extended & merged default palette colors
  $enriched-palette: map.deep-merge($palette, $override-palette);

  // Extended colors with final palette, colors preset apply separately from palette
  $colors-preset: map.deep-merge(
    build-colors-preset($enriched-palette),
    $override-colors-preset
  );

  // Extended & override default accents map
  $accents-preset: map.deep-merge(
    $default-accents-preset,
    $override-accents-preset
  );

  
  // Get global default mappers & merge it
  $default-accents-context: accents-context-collect();
  $accents-context: map.deep-merge($default-accents-context, $accents-context);

  // Apply
  @include apply-accents-preset($accents-preset, $accents-context);
  @include apply-accents-preset($colors-preset, $accents-context);
}

// @in:
//   $variants: VariantsContext
@mixin setup-variants($variants-context: ()) {
  $variants-context: if($variants-context != null, $variants-context, ());
  $default-variants-context: variants-context-collect();

  $variants-context: map.deep-merge(
    $default-variants-context,
    $variants-context
  );

  @include apply-variants-preset($variants-context);
}
