@use 'sass:map';
@use 'sass:list';
@use 'sass:color';
@use './variables';

// convenience
@function quick-define-dbx-config-via-banners($top-banner: 0px, $bottom-banner: 0px) {
  @return ('layout': ('top-banner-height': $top-banner, 'bottom-banner-height': $bottom-banner));
}

// theme
@function define-dbx-theme-config($theme-config, $input-dbx-theme-config: null) {
  @if ($input-dbx-theme-config == null) {
    $input-dbx-theme-config: ();
  }

  $input-dbx-screen-theme-config: map.get($input-dbx-theme-config, 'screen');
  $input-dbx-layout-theme-config: map.get($input-dbx-theme-config, 'layout');
  $input-dbx-extension-theme-config: map.get($input-dbx-theme-config, 'extension');

  $dbx-screen: define-dbx-screen-config($input-dbx-screen-theme-config);
  $dbx-layout: define-dbx-layout-config($input-dbx-layout-theme-config);
  $dbx-extension: define-dbx-extension-config($input-dbx-extension-theme-config);

  $dbx-theme-config: (
    'screen': $dbx-screen,
    'layout': $dbx-layout,
    'extension': $dbx-extension
  );

  @return map.merge(
    $theme-config,
    (
      'dbx': $dbx-theme-config
    )
  );
}

@function get-dbx-theme-config($theme-config) {
  @return map.get($theme-config, 'dbx');
}

// screen
@function define-dbx-screen-config($input-dbx-theme-screen-config: null) {
  $dbx-screen-config: (
    'mobile': 360px,
    // 0-360px
    'small': 520px,
    //361-520px
    'medium': 768px,
    //521-768px
    'large': 1280px,
    //769-1280px
    'tiny-vertical': 280px //0-280px
  );

  @if ($input-dbx-theme-screen-config != null) {
    $dbx-screen-config: map.merge($dbx-screen-config, $input-dbx-theme-screen-config);
  }

  @return $dbx-screen-config;
}

@function get-dbx-screen-config($theme-config) {
  @return map.get(get-dbx-theme-config($theme-config), 'screen');
}

// layout
$default-ok-color: color.scale(blue, $lightness: 30%);
$default-success-color: green;
$default-notice-color: #f28600;

@function define-dbx-layout-config($input-dbx-theme-layout-config: null) {
  $dbx-layout-config: (
    // banner
    'top-banner-height': 0px,
    'bottom-banner-height': 0px,
    // navbars
    'page-navbar-height': 52px,
    // initial main navbar height
    'content-navbar-height': 56px,
    // initial content navbar height
    // content
    'box-max-width': 600px,
    // initial max width of box content, such as popups.
    'content-max-width': 1200px,
    // initial max width of restricted-width content
    // padding
    'padding-0': 0px,
    // initial padding-0
    'padding-1': 2px,
    // initial padding-1
    'padding-2': 6px,
    // initial padding-2
    'padding-3': 12px,
    // initial padding-3
    'padding-4': 18px,
    // initial padding-4
    'padding-5': 24px,
    // initial padding-5
    // layout
    'two-column-left-width': 320px,
    // colors - NOTE: other colors come from Angular Material
    'success-color': $default-success-color,
    'ok-color': $default-ok-color,
    'notice-color': $default-notice-color,
    // avatar
    'dbx-avatar-size': 64px,
    'dbx-avatar-large-size': 128px,
    'dbx-avatar-small-size': 32px
  );

  @if ($input-dbx-theme-layout-config != null) {
    $dbx-layout-config: map.merge($dbx-layout-config, $input-dbx-theme-layout-config);
  }

  @return $dbx-layout-config;
}

@function get-dbx-layout-config($theme-config) {
  @return map.get(get-dbx-theme-config($theme-config), 'layout');
}

@function get-dbx-layout-config-var($theme-config, $item) {
  @return map.get(get-dbx-layout-config($theme-config), $item);
}

@function get-dbx-layout-top-banner-height($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'top-banner-height');
}

@function get-dbx-layout-bottom-banner-height($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'bottom-banner-height');
}

@function get-dbx-layout-page-navbar-height($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'page-navbar-height');
}

@function get-dbx-layout-content-navbar-height($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'content-navbar-height');
}

@function get-dbx-layout-content-max-width($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'content-max-width');
}

@function get-dbx-layout-box-max-width($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'box-max-width');
}

@function get-dbx-layout-padding($theme-config, $padding-level) {
  @return get-dbx-layout-config-var($theme-config, 'padding-' + $padding-level);
}

@function get-dbx-two-column-left-width($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'two-column-left-width');
}

@function get-dbx-success-color($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'success-color');
}

@function get-dbx-ok-color($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'ok-color');
}

@function get-dbx-notice-color($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'notice-color');
}

@function get-dbx-avatar-size($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'dbx-avatar-size');
}

@function get-dbx-avatar-large-size($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'dbx-avatar-large-size');
}

@function get-dbx-avatar-small-size($theme-config) {
  @return get-dbx-layout-config-var($theme-config, 'dbx-avatar-small-size');
}

// extension
@function define-dbx-extension-config($input-dbx-theme-extension-config: null) {
  $dbx-extension-config: (
    // calendar enabled by default
    'calendar': 1,
    // table enabled by default
    'table': 1,
    // zip enabled by default
    'zip': 1,
    // help enabled by default
    'help': 1,
    // mapbox enabled by default
    'mapbox': 1
  );

  @if ($input-dbx-theme-extension-config != null) {
    $dbx-extension-config: map.merge($dbx-extension-config, $input-dbx-theme-extension-config);
  }

  @return $dbx-extension-config;
}

@function get-dbx-extension-config($theme-config) {
  @return map.get(get-dbx-theme-config($theme-config), 'extension');
}

@function get-dbx-extension-config-var($theme-config, $item) {
  @return map.get(get-dbx-extension-config($theme-config), $item);
}

@function get-dbx-extension-calendar-enabled($theme-config) {
  @return get-dbx-extension-config-var($theme-config, 'calendar');
}

@function get-dbx-extension-table-enabled($theme-config) {
  @return get-dbx-extension-config-var($theme-config, 'table');
}

@function get-dbx-extension-zip-enabled($theme-config) {
  @return get-dbx-extension-config-var($theme-config, 'zip');
}

@function get-dbx-extension-help-enabled($theme-config) {
  @return get-dbx-extension-config-var($theme-config, 'help');
}

@function get-dbx-extension-mapbox-enabled($theme-config) {
  @return get-dbx-extension-config-var($theme-config, 'mapbox');
}
