var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
import { u as uuidv4 } from "./chunk.dcf-utility.js?v=6.1.1";
import { D as DCFButtonToggles } from "./chunk.dcf-button-toggle.js?v=6.1.1";
class DCFCollapsibleFieldsets {
  static {
    __name(this, "DCFCollapsibleFieldsets");
  }
  uuid = uuidv4();
  fieldsetElement = null;
  legendElement = null;
  legendButtonElement = null;
  innerDivElement = null;
  legendButtonClassList = [
    "dcf-btn",
    "dcf-btn-tertiary",
    "dcf-d-inline-block",
    "dcf-pt-0",
    "dcf-pb-0",
    "dcf-pl-1",
    "dcf-pr-1",
    "dcf-mr-2"
  ];
  legendButtonInnerHTMLOn = "-";
  legendButtonInnerHTMLOff = "+";
  fieldsetContentsClassList = [];
  fieldsetContentsClassListOn = [
    "dcf-h-auto"
  ];
  fieldsetContentsClassListOff = [
    "dcf-h-0",
    "dcf-overflow-y-hidden",
    "dcf-overflow-x-hidden"
  ];
  fieldsetClassList = [];
  fieldsetClassListOn = [];
  fieldsetClassListOff = [
    "dcf-pt-0",
    "dcf-pb-0"
  ];
  animationBlockClassList = [
    "dcf-motion-none"
  ];
  commandToggle = new Event(DCFButtonToggles.events("commandToggle"));
  toggleKeys = [];
  onKeys = [];
  offKeys = [];
  // Set up the button
  constructor(fieldset, options = {}) {
    Array.isArray(options.toggleKeys) ? this.toggleKeys = [...options.toggleKeys] : options.toggleKeys !== null && options.toggleKeys !== void 0 && options.toggleKeys !== "" && this.toggleKeys.push(options.toggleKeys), Array.isArray(options.onKeys) ? this.onKeys = [...options.onKeys] : options.onKeys !== null && options.onKeys !== void 0 && options.onKeys !== "" && this.onKeys.push(options.onKeys), Array.isArray(options.offKeys) ? this.offKeys = [...options.offKeys] : options.offKeys !== null && options.offKeys !== void 0 && options.offKeys !== "" && this.offKeys.push(options.offKeys), "legendButtonClassList" in options && Array.isArray(options.legendButtonClassList) && (this.legendButtonClassList = options.legendButtonClassList), "legendButtonInnerHTMLOn" in options && typeof options.legendButtonInnerHTMLOn == "string" && (this.legendButtonInnerHTMLOn = options.legendButtonInnerHTMLOn), "legendButtonInnerHTMLOff" in options && typeof options.legendButtonInnerHTMLOff == "string" && (this.legendButtonInnerHTMLOff = options.legendButtonInnerHTMLOff), "fieldsetContentsClassList" in options && Array.isArray(options.fieldsetContentsClassList) && (this.fieldsetContentsClassList = options.fieldsetContentsClassList), "fieldsetContentsClassListOn" in options && Array.isArray(options.fieldsetContentsClassListOn) && (this.fieldsetContentsClassListOn = options.fieldsetContentsClassListOn), "fieldsetContentsClassListOff" in options && Array.isArray(options.fieldsetContentsClassListOff) && (this.fieldsetContentsClassListOff = options.fieldsetContentsClassListOff), "fieldsetClassList" in options && Array.isArray(options.fieldsetClassList) && (this.fieldsetClassList = options.fieldsetClassList), "fieldsetClassListOn" in options && Array.isArray(options.fieldsetClassListOn) && (this.fieldsetClassListOn = options.fieldsetClassListOn), "fieldsetClassListOff" in options && Array.isArray(options.fieldsetClassListOff) && (this.fieldsetClassListOff = options.fieldsetClassListOff), "animationBlockClassList" in options && Array.isArray(options.animationBlockClassList) && (this.animationBlockClassList = options.animationBlockClassList), this.fieldsetElement = fieldset, (this.fieldsetElement.getAttribute("id") === "" || this.fieldsetElement.getAttribute("id") === null) && this.fieldsetElement.setAttribute("id", this.uuid.concat("-collapsible-fieldset"));
    let fieldsetStartExpanded = this.fieldsetElement.dataset.startExpanded;
    fieldsetStartExpanded === void 0 && (fieldsetStartExpanded = "true");
    const legend = this.fieldsetElement.querySelector("legend");
    if (legend === null)
      throw new Error("Missing Legend In Fieldset");
    this.legendElement = legend.cloneNode(!0), legend.remove(), this.legendElement.style.cursor = "pointer", this.innerDivElement = document.createElement("div"), this.innerDivElement.setAttribute("id", this.uuid.concat("-collapsible-fieldset-contents")), this.fieldsetContentsClassList.forEach((divClass) => {
      this.innerDivElement.classList.add(divClass);
    }), fieldsetStartExpanded === "true" ? this.fieldsetContentsClassListOn.forEach((divClass) => {
      this.innerDivElement.classList.add(divClass);
    }) : this.fieldsetContentsClassListOff.forEach((divClass) => {
      this.innerDivElement.classList.add(divClass);
    }), Array.from(fieldset.childNodes).forEach((node) => {
      this.innerDivElement.appendChild(node);
    }), this.fieldsetElement.append(this.legendElement), this.fieldsetElement.append(this.innerDivElement), this.animationBlockClassList.forEach((fieldsetClass) => {
      this.fieldsetElement.classList.add(fieldsetClass);
    }), this.fieldsetClassList.forEach((fieldsetClass) => {
      this.fieldsetElement.classList.add(fieldsetClass);
    }), fieldsetStartExpanded === "true" ? this.fieldsetClassListOn.forEach((fieldsetClass) => {
      this.fieldsetElement.classList.add(fieldsetClass);
    }) : this.fieldsetClassListOff.forEach((fieldsetClass) => {
      this.fieldsetElement.classList.add(fieldsetClass);
    }), this.legendButtonElement = document.createElement("button"), this.legendButtonClassList.forEach((btnClass) => {
      this.legendButtonElement.classList.add(btnClass);
    }), this.legendButtonElement.innerHTML = this.legendButtonInnerHTMLOn, this.legendButtonElement.setAttribute("type", "button"), this.legendButtonElement.dataset.controls = this.innerDivElement.getAttribute("id"), this.legendButtonElement.dataset.labelOn = "Expand Fieldset", this.legendButtonElement.dataset.labelOff = "Collapse Fieldset", this.legendButtonElement.dataset.startExpanded = fieldsetStartExpanded, this.legendElement.prepend(this.legendButtonElement), this.#setEventListeners(), new DCFButtonToggles(this.legendButtonElement, {
      toggleKeys: this.toggleKeys,
      onKeys: this.onKeys,
      offKeys: this.offKeys
    }), this.fieldsetElement.classList.add("dcf-collapsible-fieldset-initialized"), this.fieldsetElement.dispatchEvent(new CustomEvent(DCFCollapsibleFieldsets.events("collapsibleFieldsetReady"), {
      detail: {
        classInstance: this
      }
    })), this.fieldsetElement.getAttribute("hidden") !== null && this.fieldsetElement.removeAttribute("hidden");
    const removeAnimationBlock = /* @__PURE__ */ __name(() => {
      this.animationBlockClassList.forEach((fieldsetClass) => {
        this.fieldsetElement.classList.remove(fieldsetClass);
      }), this.fieldsetElement.removeEventListener("transitionend", removeAnimationBlock);
    }, "removeAnimationBlock");
    this.fieldsetElement.addEventListener("transitionend", removeAnimationBlock);
  }
  // The names of the events to be used easily
  static events(name) {
    const events = {
      collapsibleFieldsetReady: "collapsibleFieldsetReady"
    };
    return Object.freeze(events), DCFButtonToggles.events(name) !== void 0 ? DCFButtonToggles.events(name) : name in events ? events[name] : void 0;
  }
  // /**
  //  * This function will update the styles and HTML for the fieldset, fieldset contents, and the button
  //  * These events we are listening for come from the DCFButtonToggles
  //  */
  #setEventListeners() {
    this.legendElement.addEventListener("click", (event) => {
      this.legendElement.contains(event.target) && !this.legendButtonElement.isEqualNode(event.target) && !this.legendButtonElement.contains(event.target) && this.legendButtonElement.dispatchEvent(this.commandToggle);
    }), this.innerDivElement.addEventListener(DCFCollapsibleFieldsets.events("toggleElementOn"), () => {
      this.fieldsetContentsClassListOff.forEach((toggleElementClass) => {
        this.innerDivElement.classList.remove(toggleElementClass);
      }), this.fieldsetContentsClassListOn.forEach((toggleElementClass) => {
        this.innerDivElement.classList.add(toggleElementClass);
      }), this.fieldsetClassListOff.forEach((fieldsetClass) => {
        this.fieldsetElement.classList.remove(fieldsetClass);
      }), this.fieldsetClassListOn.forEach((fieldsetClass) => {
        this.fieldsetElement.classList.add(fieldsetClass);
      });
    }), this.innerDivElement.addEventListener(DCFCollapsibleFieldsets.events("toggleElementOff"), () => {
      this.fieldsetContentsClassListOn.forEach((toggleElementClass) => {
        this.innerDivElement.classList.remove(toggleElementClass);
      }), this.fieldsetContentsClassListOff.forEach((toggleElementClass) => {
        this.innerDivElement.classList.add(toggleElementClass);
      }), this.fieldsetClassListOn.forEach((fieldsetClass) => {
        this.fieldsetElement.classList.remove(fieldsetClass);
      }), this.fieldsetClassListOff.forEach((fieldsetClass) => {
        this.fieldsetElement.classList.add(fieldsetClass);
      });
    }), this.legendButtonElement.addEventListener(DCFCollapsibleFieldsets.events("toggleButtonOn"), () => {
      this.legendButtonElement.innerHTML = this.legendButtonInnerHTMLOn;
    }), this.legendButtonElement.addEventListener(DCFCollapsibleFieldsets.events("toggleButtonOff"), () => {
      this.legendButtonElement.innerHTML = this.legendButtonInnerHTMLOff;
    });
  }
}
class UNLCollapsibleFieldset extends DCFCollapsibleFieldsets {
  static {
    __name(this, "UNLCollapsibleFieldset");
  }
  constructor(fieldset, options = {}) {
    "legendButtonInnerHTMLOn" in options || (options.legendButtonInnerHTMLOn = `<svg xmlns='http://www.w3.org/2000/svg' class='dcf-h-4 dcf-w-4 dcf-fill-current' viewBox='0 0 24 24'>
    <path d='M21.3,9.4l-18.7,0C1.2,9.4,0,10.6,0,12c0,0.7,0.3,1.4,0.8,1.9c0.5,0.5,1.2,0.8,1.9,0.8h18.7
        c1.4,0,2.6-1.2,2.6-2.6C24,10.6,22.8,9.4,21.3,9.4z'/>
    <g>
        <path fill='none' d='M0,0h24v24H0V0z'/>
    </g>
</svg>`), "legendButtonInnerHTMLOff" in options || (options.legendButtonInnerHTMLOff = `<svg xmlns='http://www.w3.org/2000/svg' class='dcf-h-4 dcf-w-4 dcf-fill-current' viewBox='0 0 24 24'>
    <path d='M21.4,9.4h-6.7V2.6C14.6,1.2,13.5,0,12,0c-1.4,0-2.6,1.2-2.6,2.6l0,6.7H2.6C1.2,9.4,0,10.6,0,12
        c0,1.4,1.2,2.6,2.6,2.6h6.8l0,6.7c0,0.7,0.3,1.4,0.8,1.9c0.5,0.5,1.2,0.8,1.9,0.8
        c1.4,0,2.6-1.2,2.6-2.6v-6.7h6.7c1.4,0,2.6-1.2,2.6-2.6C24,10.6,22.8,9.4,21.4,9.4z'/>
    <g>
        <path fill='none' d='M0,0h24v24H0V0z'/>
    </g>
</svg>`), "fieldsetClassListOff" in options || (options.fieldsetClassListOff = [
      "dcf-pt-0",
      "dcf-pb-0",
      "unl-collapsible-fieldset-close"
    ]), "fieldsetClassListOn" in options || (options.fieldsetClassListOn = [
      "unl-collapsible-fieldset-open"
    ]), "fieldsetContentsClassListOn" in options || (options.fieldsetContentsClassListOn = [
      "dcf-max-h-inf",
      "unl-collapsible-fieldset-contents-open"
    ]), "fieldsetContentsClassListOff" in options || (options.fieldsetContentsClassListOff = [
      "dcf-max-h-0",
      "dcf-overflow-y-hidden",
      "dcf-overflow-x-hidden",
      "unl-collapsible-fieldset-contents-close"
    ]), super(fieldset, options), window.UNL = window.UNL || {}, window.UNL.classes = window.UNL.classes || {}, window.UNL.classes[this.fieldsetElement.getAttribute("id")] = this, this.fieldsetElement.dispatchEvent(new Event("UNLClassReady"));
  }
}
export {
  DCFCollapsibleFieldsets as D,
  UNLCollapsibleFieldset as U
};
//# sourceMappingURL=chunk.unl-collapsible-fieldset.js.map
