import { Component, Element, Event, Host, Prop, State, Watch, h } from '@stencil/core';
import { createColorClasses, hostContext } from '../../utils/theme';
export class GascoLabel {
  constructor() {
    this.inRange = false;
    this.noAnimate = false;
  }
  componentWillLoad() {
    this.inRange = !!this.el.closest('gasco-range');
    this.noAnimate = this.position === 'floating';
    this.emitStyle();
    this.emitColor();
  }
  componentDidLoad() {
    if (this.noAnimate) {
      setTimeout(() => {
        this.noAnimate = false;
      }, 1000);
    }
  }
  colorChanged() {
    this.emitColor();
  }
  positionChanged() {
    this.emitStyle();
  }
  emitColor() {
    const { color } = this;
    this.gascoColor.emit({
      'item-label-color': color !== undefined,
      [`gasco-color-${color}`]: color !== undefined,
    });
  }
  emitStyle() {
    const { inRange, position } = this;
    // If the label is inside of a range we don't want
    // to override the classes added by the label that
    // is a direct child of the item
    if (!inRange) {
      this.gascoStyle.emit({
        label: true,
        [`label-${position}`]: position !== undefined,
      });
    }
  }
  render() {
    const position = this.position;
    return (h(Host, { class: createColorClasses(this.color, {
        'in-item-color': hostContext('gasco-item.gasco-color', this.el),
        [`label-${position}`]: position !== undefined,
        [`label-no-animate`]: this.noAnimate,
        'label-rtl': document.dir === 'rtl',
      }) }));
  }
  static get is() { return "gasco-label"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["gasco-label.md.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["gasco-label.md.css"]
  }; }
  static get properties() { return {
    "color": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "Color",
        "resolved": "\"danger\" | \"dark\" | \"light\" | \"medium\" | \"primary\" | \"secondary\" | \"success\" | \"tertiary\" | \"warning\" | string & Record<never, never>",
        "references": {
          "Color": {
            "location": "import",
            "path": "../../interface"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "The color to use from your application's color palette.\nDefault options are: `\"primary\"`, `\"secondary\"`, `\"tertiary\"`, `\"success\"`, `\"warning\"`, `\"danger\"`, `\"light\"`, `\"medium\"`, and `\"dark\"`.\nFor more information on colors, see [theming](/docs/theming/basics)."
      },
      "attribute": "color",
      "reflect": true
    },
    "position": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'fixed' | 'stacked' | 'floating'",
        "resolved": "\"fixed\" | \"floating\" | \"stacked\"",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "The position determines where and how the label behaves inside an item."
      },
      "attribute": "position",
      "reflect": false
    }
  }; }
  static get states() { return {
    "noAnimate": {}
  }; }
  static get events() { return [{
      "method": "gascoColor",
      "name": "gascoColor",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "internal",
            "text": undefined
          }],
        "text": "Emitted when the color changes."
      },
      "complexType": {
        "original": "StyleEventDetail",
        "resolved": "StyleEventDetail",
        "references": {
          "StyleEventDetail": {
            "location": "import",
            "path": "../../interface"
          }
        }
      }
    }, {
      "method": "gascoStyle",
      "name": "gascoStyle",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "internal",
            "text": undefined
          }],
        "text": "Emitted when the styles change."
      },
      "complexType": {
        "original": "StyleEventDetail",
        "resolved": "StyleEventDetail",
        "references": {
          "StyleEventDetail": {
            "location": "import",
            "path": "../../interface"
          }
        }
      }
    }]; }
  static get elementRef() { return "el"; }
  static get watchers() { return [{
      "propName": "color",
      "methodName": "colorChanged"
    }, {
      "propName": "position",
      "methodName": "positionChanged"
    }]; }
}
