import { h } from '@stencil/core';
export class Accordion {
  constructor() {
    this.accGroup = null;
    this.accheaders = null;
    this.accBodies = null;
    this.isOpen = false;
    this.numberElement = null;
    this.condition = false;
    this.startOpen = false;
  }
  async toggle() {
    this.isOpen = !this.isOpen;
    this.bdsToggle.emit({ value: this.isOpen });
  }
  async open() {
    this.isOpen = true;
  }
  async close() {
    var _a, _b;
    (_a = this.accheaders) === null || _a === void 0 ? void 0 : _a.close();
    (_b = this.accBodies) === null || _b === void 0 ? void 0 : _b.close();
    this.isOpen = false;
  }
  // Método interno
  async notStart() {
    this.startOpen = false;
  }
  // Método interno
  async reciveNumber(number) {
    this.numberElement = number;
  }
  isOpenChanged(value) {
    var _a, _b, _c, _d, _e, _f, _g;
    if (this.accGroup.collapse == 'single' && this.condition === false) {
      (_a = this.accheaders) === null || _a === void 0 ? void 0 : _a.toggle();
      (_b = this.accBodies) === null || _b === void 0 ? void 0 : _b.toggle();
      (_c = this.accGroup) === null || _c === void 0 ? void 0 : _c.closeAll(this.numberElement);
    }
    else {
      if (value) {
        (_d = this.accheaders) === null || _d === void 0 ? void 0 : _d.open();
        (_e = this.accBodies) === null || _e === void 0 ? void 0 : _e.open();
        this.bdsAccordionOpen.emit();
      }
      else {
        (_f = this.accheaders) === null || _f === void 0 ? void 0 : _f.close();
        (_g = this.accBodies) === null || _g === void 0 ? void 0 : _g.close();
        this.bdsAccordionClose.emit();
      }
    }
    this.condition = false;
  }
  componentWillLoad() {
    this.accGroup =
      this.element.parentElement.tagName == 'BDS-ACCORDION-GROUP' &&
        this.element.parentElement;
    this.accheaders = this.element.children[0];
    this.accBodies = this.element.children[1];
    if (this.startOpen === true) {
      this.condition = true;
      this.isOpen = true;
    }
  }
  render() {
    return (h("div", { class: "accordion_group" }, h("slot", null)));
  }
  static get is() { return "bds-accordion"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["accordion.scss"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["accordion.css"]
    };
  }
  static get properties() {
    return {
      "startOpen": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": true,
        "docs": {
          "tags": [],
          "text": "A prop for make the accordion open when is render."
        },
        "attribute": "start-open",
        "reflect": false,
        "defaultValue": "false"
      }
    };
  }
  static get states() {
    return {
      "isOpen": {},
      "numberElement": {},
      "condition": {}
    };
  }
  static get events() {
    return [{
        "method": "bdsToggle",
        "name": "bdsToggle",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "bdsToggle. Event to return value of toggle."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "bdsAccordionOpen",
        "name": "bdsAccordionOpen",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "bdsAccordionOpen. Event to return value when accordion is open."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }, {
        "method": "bdsAccordionClose",
        "name": "bdsAccordionClose",
        "bubbles": true,
        "cancelable": true,
        "composed": true,
        "docs": {
          "tags": [],
          "text": "bdsAccordionOpen. Event to return value when accordion is closed."
        },
        "complexType": {
          "original": "any",
          "resolved": "any",
          "references": {}
        }
      }];
  }
  static get methods() {
    return {
      "toggle": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      },
      "open": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      },
      "close": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      },
      "notStart": {
        "complexType": {
          "signature": "() => Promise<void>",
          "parameters": [],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      },
      "reciveNumber": {
        "complexType": {
          "signature": "(number: any) => Promise<void>",
          "parameters": [{
              "tags": [],
              "text": ""
            }],
          "references": {
            "Promise": {
              "location": "global"
            }
          },
          "return": "Promise<void>"
        },
        "docs": {
          "text": "",
          "tags": []
        }
      }
    };
  }
  static get elementRef() { return "element"; }
  static get watchers() {
    return [{
        "propName": "isOpen",
        "methodName": "isOpenChanged"
      }];
  }
}
