// stylelint-disable max-line-length
@use 'sass:map';
@use '../mixins' as *;
@use '../functions' as *;
@use '../config' as *;
@use '../schemas/charts' as *;
@use '../../utils' as *;
@use '../../typography/mixins' as *;
@use '../../typography/functions' as *;

////
/// @package theming
/// @group themes
/// @access public
/// @author <a href="https://github.com/simeonoff" target="_blank">Simeon Simeonoff</a>
////

/// @param {Map} $schema [$light-material-schema] - The schema used as basis for styling the component.
/// @param {List} $brushes [series] - Defines the palette from which automatically assigned series colors are selected.
/// @param {List} $outlines [series] - Defines the palette from which automatically assigned series outline colors are selected.
/// @param {Number} $label-extent [null] - Sets the pixel amount by which the labels are offset from the edge of the slices.
/// @param {Color} $label-inner-color [null] - Sets the color for labels rendered inside of the pie chart.
/// @param {Color} $label-outer-color [null] - Sets the color for labels rendered outside of the pie chart.
/// @param {String} $labels-position [null] - Sets the position of chart labels. Valid values are: 'none', 'center', 'insideEnd', 'outsideEnd', and 'bestFit'.
/// @param {Number} $leader-line-margin [null] - Sets the margin between a label and the end of its leader line.
/// @param {String} $leader-line-type [null] - Sets what type of leader lines will be used for the outside end labels. Valid values are: 'straight', 'spline', and 'arc'.
/// @param {String} $leader-line-visibility [null] - Sets whether the leader lines are visible. Valid values are: 'visible' and 'collapsed'.
/// @param {Number} $radius-factor [null] - Sets the scaling factor of the chart's radius. Value between 0 and 1.
/// @requires {function} extend
///
/// @example scss
///   $my-chart-theme: pie-chart-theme($brushes: (red, orange, blue));
///   // Pass the theme to the css-vars mixin
///   @include css-vars($my-chart-theme);
@function pie-chart-theme(
    $schema: $light-material-schema,
    $target: 'angular',

    $brushes: null,
    $outlines: null,
    $label-extent: null,
    $label-inner-color: null,
    $label-outer-color: null,
    $labels-position: null,
    $leader-line-margin: null,
    $leader-line-type: null,
    $leader-line-visibility: null,
    $radius-factor: null
) {
    $name: 'pie-chart';
    $selector: #{element-prefix()}-#{$name};
    $chart-schema: ();

    @if map.has-key($schema, $name) {
        $chart-schema: map.get($schema, $name);
    } @else {
        $chart-schema: $schema;
    }

    $theme: digest-schema($chart-schema);

    @return extend(
        $theme,
        (
            name: $name,
            selector: $selector,
            brushes: $brushes,
            outlines: $outlines,
            label-extent: $label-extent,
            label-inner-color: $label-inner-color,
            label-outer-color: $label-outer-color,
            labels-position: $labels-position,
            leader-line-margin: $leader-line-margin,
            leader-line-type: $leader-line-type,
            leader-line-visibility: $leader-line-visibility,
            radius-factor: $radius-factor,
        )
    );
}

/// Adds typography styles for the pie-chart component.
/// Uses the 'body-2'
/// category from the typographic scale.
/// @group typography
/// @param {Map} $type-scale - A typographic scale as produced by type-scale.
/// @param {Map} $categories [(text: 'body-2')] - The categories from the typographic scale used for type styles.
/// @requires {mixin} type-style
@mixin pie-chart-typography($type-scale, $categories: (text: 'body-2'), $target: 'angular') {
    $name: 'pie-chart';
    $selector: #{element-prefix()}-#{$name};
    $text: map.get($categories, 'text');
    $text-styles: type-scale-category($type-scale, $text);

    #{$selector} {
        @include font-var('text-style', $text-styles, $name);
    }
}
