'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-223abef7.js');

const styleCss$2 = "smoothly-accordion-item.sc-smoothly-accordion{border:1px solid rgb(var(--smoothly-dark-color));border-bottom:none}smoothly-accordion-item.sc-smoothly-accordion:first-of-type{border-top-left-radius:4px;border-top-right-radius:4px;margin-top:.4em}smoothly-accordion-item.sc-smoothly-accordion:last-of-type{border-bottom-left-radius:4px;border-bottom-right-radius:4px;border-bottom:1px solid rgb(var(--smoothly-dark-color));margin-bottom:.6em}smoothly-accordion-item[open].sc-smoothly-accordion{border-color:rgb(var(--smoothly-primary-color));border-bottom:1px solid rgb(var(--smoothly-primary-color))}smoothly-accordion-item[open].sc-smoothly-accordion+smoothly-accordion-item.sc-smoothly-accordion{border-top:none}";

const SmoothlyAccordion = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.items = [];
  }
  valueChanged(value) {
    this.updateItems();
  }
  handleOpenClose(event) {
    if (event.detail.open)
      this.value = event.detail.name;
    else if (this.value == event.detail.name)
      this.value = undefined;
  }
  onAccordionItemDidLoad(ev) {
    const item = ev.target;
    this.items.push(item);
    if (this.value == undefined && item.open)
      this.value = item.name;
    else
      this.updateItems();
  }
  onAccordionItemDidUnload(ev) {
    const index = this.items.indexOf(ev.target);
    if (index > -1)
      this.items.splice(index, 1);
  }
  componentDidLoad() {
    this.updateItems();
  }
  updateItems() {
    let hasChecked = false;
    for (const item of this.items)
      if ((item.open = !hasChecked && item.name == this.value))
        hasChecked = true;
  }
  render() {
    return [index.h("slot", null)];
  }
  get me() { return index.getElement(this); }
  static get watchers() { return {
    "value": ["valueChanged"]
  }; }
};
SmoothlyAccordion.style = styleCss$2;

const styleCss$1 = ".sc-smoothly-accordion-item-h{display:block}[hidden].sc-smoothly-accordion-item-h{display:none}details.sc-smoothly-accordion-item{padding:0}details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item>span.sc-smoothly-accordion-item{float:right;margin:.2em;font-size:60%}details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item{font-size:120%;list-style-type:none;cursor:pointer;padding:.4em;color:rgb(var(--smoothly-text-tint))}details.sc-smoothly-accordion-item>fieldset.sc-smoothly-accordion-item{border:none;margin:0;padding:0}[open].sc-smoothly-accordion-item-h>details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item{color:rgb(var(--smoothly-primary-contrast));background:rgb(var(--smoothly-primary-color))}details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item::-webkit-details-marker{display:none}details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item>svg.sc-smoothly-accordion-item{width:1em;height:auto;margin-bottom:-.2em;margin-right:.4em}[open].sc-smoothly-accordion-item-h>details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item>svg.sc-smoothly-accordion-item{fill:rgb(var(--smoothly-primary-contrast))}.sc-smoothly-accordion-item-h:not([open])>details.sc-smoothly-accordion-item>summary.sc-smoothly-accordion-item>svg.sc-smoothly-accordion-item{fill:rgb(var(--smoothly-text-tint))}";

const SmoothlyAccordionItem = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.smoothlyAccordionItemDidLoad = index.createEvent(this, "smoothlyAccordionItemDidLoad", 7);
    this.smoothlyAccordionItemDidUnload = index.createEvent(this, "smoothlyAccordionItemDidUnload", 7);
    this.smoothlyOpen = index.createEvent(this, "smoothlyOpen", 7);
    this.smoothlyClose = index.createEvent(this, "smoothlyClose", 7);
  }
  openChanged(isChecked) {
    this.open = isChecked;
    if (isChecked) {
      this.smoothlyOpen.emit({
        open: true,
        name: this.name,
      });
    }
  }
  componentDidLoad() {
    const summary = this.me.getElementsByTagName("summary");
    if (summary.length > 0) {
      const onClick = (e) => {
        if (this.open)
          this.smoothlyClose.emit({ open: this.open, name: this.name });
        else
          this.open = true;
        e.preventDefault();
      };
      summary[0].addEventListener("click", onClick);
      summary[0].addEventListener("touch", onClick);
    }
    this.smoothlyAccordionItemDidLoad.emit();
  }
  disconnectedCallback() {
    this.smoothlyAccordionItemDidUnload.emit();
  }
  render() {
    return (index.h("details", { open: this.open }, index.h("summary", null, this.open ? (index.h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512" }, index.h("path", { d: "M256 48C141.6 48 48 141.6 48 256s93.6 208 208 208 208-93.6 208-208S370.4 48 256 48zm-42.7 318.9L106.7 260.3l29.9-29.9 76.8 76.8 162.1-162.1 29.9 29.9-192.1 191.9z" }))) : (index.h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512" }, index.h("path", { d: "M256 48C141.601 48 48 141.601 48 256s93.601 208 208 208 208-93.601 208-208S370.399 48 256 48zm0 374.399c-91.518 0-166.399-74.882-166.399-166.399S164.482 89.6 256 89.6 422.4 164.482 422.4 256 347.518 422.399 256 422.399z" }))), this.name, typeof this.brand == "string" ? (index.h("span", { class: this.brand.toLowerCase() }, this.brand)) : Array.isArray(this.brand) ? (this.brand.map(b => index.h("span", { class: b.toLowerCase() }, b))) : ([])), index.h("fieldset", { disabled: !this.open, name: this.name }, index.h("slot", null))));
  }
  get me() { return index.getElement(this); }
  static get watchers() { return {
    "open": ["openChanged"]
  }; }
};
SmoothlyAccordionItem.style = styleCss$1;

const styleCss = ".sc-smoothly-radio-h{display:block;position:relative}[hidden].sc-smoothly-radio-h{display:none}label.sc-smoothly-radio{display:block;width:calc(100% - 2 * .4em);padding:.2em .4em .2em .4em}input[type=\"radio\"].sc-smoothly-radio{position:absolute;left:0;top:0;width:calc(100%);height:100%;margin:0;-moz-appearance:none;appearance:none;-webkit-appearance:none}input[type=\"radio\"].sc-smoothly-radio~label.sc-smoothly-radio{border:1px solid rgb(var(--smoothly-color-shade));color:rgb(var(--smoothly-color-tint));background:rgb(var(--smoothly-color-shade))}input[type=\"radio\"].sc-smoothly-radio:checked~label.sc-smoothly-radio{background-color:rgb(var(--smoothly-color));color:rgb(var(--smoothly-color-contrast))}";

const SmoothlyRadio = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.smoothlySelected = index.createEvent(this, "smoothlySelected", 7);
  }
  async onInput(e) {
    if (e.target && e.target.value && (this.checked = e.target.checked))
      this.smoothlySelected.emit({ name: this.name, value: this.value });
    return true;
  }
  render() {
    return [
      index.h("input", { type: "radio", name: this.name, id: this.value, tabindex: this.tabIndex, checked: this.checked, value: this.value, onChange: e => this.onInput(e) }),
      index.h("label", { htmlFor: this.value }, index.h("slot", null)),
    ];
  }
};
SmoothlyRadio.style = styleCss;

exports.smoothly_accordion = SmoothlyAccordion;
exports.smoothly_accordion_item = SmoothlyAccordionItem;
exports.smoothly_radio = SmoothlyRadio;
