import { Component, h, Host, Prop } from '@stencil/core';
const getRadius = (scale = 'medium') => {
  switch (scale) {
    case 'large':
      return 20;
    case 'small':
      return 12;
    case 'medium':
    default:
      return 16;
  }
};
const getStroke = (scale = 'medium') => {
  switch (scale) {
    case 'large':
      return 5;
    case 'small':
      return 3;
    case 'medium':
    default:
      return 4;
  }
};
/**
 * Displays a circle progress bar. It can be used either as a loading indicator that rotates indefinitely
 * or a definite progress that shows the percentage.
 */
export class DvnProgress {
  constructor() {
    /**
     * Removes the outer spacing.
     */
    this.leaned = false;
    /**
     * Shows the progress in 'loading' state.
     */
    this.indefinite = false;
    /**
     * Sets the percentage of the progress.
     */
    this.percent = 0;
    /**
     * Sets the scale.
     */
    this.scale = 'medium';
    /**
     * Sets the tint.
     */
    this.tint = 'neutral';
  }
  render() {
    const percent = this.indefinite ? 25 : this.percent;
    const stroke = this.strokeWidth || getStroke(this.scale);
    const radius = this.size ? this.size / 2 : getRadius(this.scale);
    const normalizedRadius = radius - (stroke / 2);
    const circumference = normalizedRadius * 2 * Math.PI;
    const offset = circumference - percent / 100 * circumference;
    const style = {};
    if (this.size) {
      style['--size'] = `${this.size}px`;
      style['--font-size'] = `${Number(this.size) / 2.8}px`;
    }
    if (this.strokeWidth) {
      style['--stroke-width'] = `${this.strokeWidth}px`;
    }
    if (this.fontColor) {
      style['--label-color'] = this.fontColor;
    }
    if (this.fontSize) {
      style['--font-size'] = this.fontSize;
    }
    if (this.strokeColor) {
      style['--stroke-color'] = this.strokeColor;
    }
    if (this.strokeBackgroundColor) {
      style['--stroke-background-color'] = this.strokeBackgroundColor;
    }
    return (h(Host, null,
      h("div", { class: {
          progress: true,
          [this.tint]: true,
          [this.scale]: true,
          leaned: this.leaned,
          separated: !this.leaned,
        }, style: style },
        h("svg", { class: {
            background: true,
          } },
          h("circle", { class: {
              background: true,
            }, fill: 'transparent', r: normalizedRadius, cx: radius, cy: radius })),
        h("svg", { class: {
            foreground: true,
          } },
          h("circle", { class: {
              foreground: true,
              rotating: this.indefinite,
            }, fill: 'transparent', r: normalizedRadius, cx: radius, cy: radius, style: {
              strokeDashoffset: `${offset}`,
              strokeDasharray: `${circumference} ${circumference}`,
            } })),
        !this.indefinite &&
          h("label", null, this.label !== undefined ? this.label : `${Math.floor(percent)}`))));
  }
  static get is() { return "dvn-progress"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-progress.css"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-progress.css"]
  }; }
  static get properties() { return {
    "fontColor": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Overrides the color of the percentage."
      },
      "attribute": "font-color",
      "reflect": false
    },
    "fontSize": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Overrides the size of the percentage."
      },
      "attribute": "font-size",
      "reflect": false
    },
    "label": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Text to show instead of percentage."
      },
      "attribute": "label",
      "reflect": false
    },
    "leaned": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Removes the outer spacing."
      },
      "attribute": "leaned",
      "reflect": false,
      "defaultValue": "false"
    },
    "indefinite": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Shows the progress in 'loading' state."
      },
      "attribute": "indefinite",
      "reflect": false,
      "defaultValue": "false"
    },
    "percent": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Sets the percentage of the progress."
      },
      "attribute": "percent",
      "reflect": false,
      "defaultValue": "0"
    },
    "scale": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "Scale",
        "resolved": "\"large\" | \"medium\" | \"small\"",
        "references": {
          "Scale": {
            "location": "import",
            "path": "../../theme"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Sets the scale."
      },
      "attribute": "scale",
      "reflect": false,
      "defaultValue": "'medium'"
    },
    "size": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Overrides the width and height of the component."
      },
      "attribute": "size",
      "reflect": false
    },
    "strokeBackgroundColor": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Overrides the stroke background color."
      },
      "attribute": "stroke-background-color",
      "reflect": false
    },
    "strokeColor": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Overrides the stroke color."
      },
      "attribute": "stroke-color",
      "reflect": false
    },
    "strokeWidth": {
      "type": "number",
      "mutable": false,
      "complexType": {
        "original": "number",
        "resolved": "number",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Overrides the stroke width."
      },
      "attribute": "stroke-width",
      "reflect": false
    },
    "tint": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "Tint",
        "resolved": "\"danger\" | \"neutral\" | \"primary\" | \"secondary\" | \"warning\"",
        "references": {
          "Tint": {
            "location": "import",
            "path": "../../theme"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Sets the tint."
      },
      "attribute": "tint",
      "reflect": false,
      "defaultValue": "'neutral'"
    }
  }; }
}
