import { MediaChromeButton } from "./media-chrome-button.js";
import { globalThis, document } from "./utils/server-safe-globals.js";
import { MediaUIEvents, MediaUIAttributes } from "./constants.js";
import { verbs } from "./labels/labels.js";
import { getBooleanAttr, setBooleanAttr } from "./utils/element-utils.js";
const { MEDIA_TIME_IS_LIVE, MEDIA_PAUSED } = MediaUIAttributes;
const { MEDIA_SEEK_TO_LIVE_REQUEST, MEDIA_PLAY_REQUEST } = MediaUIEvents;
const indicatorSVG = '';
const slotTemplate = document.createElement("template");
slotTemplate.innerHTML = /*html*/
`
${indicatorSVG}
${/*
A new line between spacer and text creates inconsistent spacing
between slotted items and default slots.
*/
""}
LIVE
`;
const updateAriaAttributes = (el) => {
const isPausedOrNotLive = el.mediaPaused || !el.mediaTimeIsLive;
const label = isPausedOrNotLive ? verbs.SEEK_LIVE() : verbs.PLAYING_LIVE();
el.setAttribute("aria-label", label);
isPausedOrNotLive ? el.removeAttribute("aria-disabled") : el.setAttribute("aria-disabled", "true");
};
class MediaLiveButton extends MediaChromeButton {
static get observedAttributes() {
return [...super.observedAttributes, MEDIA_PAUSED, MEDIA_TIME_IS_LIVE];
}
constructor(options = {}) {
super({ slotTemplate, ...options });
}
connectedCallback() {
updateAriaAttributes(this);
super.connectedCallback();
}
attributeChangedCallback(attrName, oldValue, newValue) {
super.attributeChangedCallback(attrName, oldValue, newValue);
updateAriaAttributes(this);
}
/**
* @type {boolean} Is the media paused
*/
get mediaPaused() {
return getBooleanAttr(this, MediaUIAttributes.MEDIA_PAUSED);
}
set mediaPaused(value) {
setBooleanAttr(this, MediaUIAttributes.MEDIA_PAUSED, value);
}
/**
* @type {boolean} Is the media playback currently live
*/
get mediaTimeIsLive() {
return getBooleanAttr(this, MediaUIAttributes.MEDIA_TIME_IS_LIVE);
}
set mediaTimeIsLive(value) {
setBooleanAttr(this, MediaUIAttributes.MEDIA_TIME_IS_LIVE, value);
}
handleClick() {
if (!this.mediaPaused && this.mediaTimeIsLive)
return;
this.dispatchEvent(
new globalThis.CustomEvent(MEDIA_SEEK_TO_LIVE_REQUEST, {
composed: true,
bubbles: true
})
);
if (this.hasAttribute(MEDIA_PAUSED)) {
this.dispatchEvent(
new globalThis.CustomEvent(MEDIA_PLAY_REQUEST, {
composed: true,
bubbles: true
})
);
}
}
}
if (!globalThis.customElements.get("media-live-button")) {
globalThis.customElements.define("media-live-button", MediaLiveButton);
}
var media_live_button_default = MediaLiveButton;
export {
media_live_button_default as default
};