import { settings } from "../settings.js";
const styles = ["purple", "gray", "red", "green", "yellow", "blue"];
class DevToolbarCard extends HTMLElement {
link;
clickAction;
shadowRoot;
_cardStyle = "purple";
get cardStyle() {
return this._cardStyle;
}
set cardStyle(value) {
if (!styles.includes(value)) {
settings.logger.error(
`Invalid style: ${value}, expected one of ${styles.join(", ")}, got ${value}.`
);
return;
}
this._cardStyle = value;
this.updateStyle();
}
static observedAttributes = ["card-style"];
constructor() {
super();
this.shadowRoot = this.attachShadow({ mode: "open" });
this.link = this.getAttribute("link");
}
attributeChangedCallback() {
if (this.hasAttribute("card-style"))
this.cardStyle = this.getAttribute("card-style");
this.updateStyle();
}
updateStyle() {
const style = this.shadowRoot.querySelector("#selected-style");
if (style) {
style.innerHTML = `
:host {
--hover-background: var(--${this.cardStyle}-hover-background);
--hover-border: var(--${this.cardStyle}-hover-border);
}
`;
}
}
connectedCallback() {
const element = this.link ? "a" : this.clickAction ? "button" : "div";
this.shadowRoot.innerHTML += `
<${element}${this.link ? ` href="${this.link}" target="_blank"` : ``} id="astro-overlay-card">
${element}>
`;
this.updateStyle();
if (this.clickAction) {
this.shadowRoot.getElementById("astro-overlay-card")?.addEventListener("click", this.clickAction);
}
}
}
export {
DevToolbarCard
};