import { efContext } from "./efContext.js";
import { playingContext } from "./playingContext.js";
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.95.0/helpers/decorate.js";
import { isEFTemporal } from "../elements/EFTemporal.js";
import { attachContextRoot } from "../attachContextRoot.js";
import { TargetOrContextMixin } from "./TargetOrContextMixin.js";
import { consume } from "@lit/context";
import { LitElement, css, html } from "lit";
import { customElement, state } from "lit/decorators.js";

//#region src/gui/EFTogglePlay.ts
attachContextRoot();
let EFTogglePlay = class EFTogglePlay$1 extends TargetOrContextMixin(LitElement, efContext) {
	constructor(..._args) {
		super(..._args);
		this.playing = false;
		this.togglePlay = () => {
			if (this.efContext) if (this.playing) this.efContext.pause();
			else {
				const playbackController = this.getPlaybackController();
				if (playbackController) try {
					const audioContext = new AudioContext({ latencyHint: "playback" });
					audioContext.resume();
					playbackController.setPendingAudioContext(audioContext);
				} catch (error) {
					console.warn("Failed to create/resume AudioContext synchronously:", error);
				}
				this.efContext.play();
			}
		};
	}
	static {
		this.styles = [css`
      :host {}
      div {
        all: inherit;
      }
    `];
	}
	get efContext() {
		return this.effectiveContext;
	}
	connectedCallback() {
		super.connectedCallback();
		this.addEventListener("click", this.togglePlay);
	}
	disconnectedCallback() {
		super.disconnectedCallback();
		this.removeEventListener("click", this.togglePlay);
	}
	render() {
		return html`
      <div>
        ${this.playing ? html`<slot name="pause"></slot>` : html`<slot name="play"></slot>`}
      </div>
    `;
	}
	getPlaybackController() {
		const context = this.efContext;
		if (!context) return null;
		if (isEFTemporal(context) && context.playbackController) return context.playbackController;
		return null;
	}
};
__decorate([consume({
	context: playingContext,
	subscribe: true
}), state()], EFTogglePlay.prototype, "playing", void 0);
EFTogglePlay = __decorate([customElement("ef-toggle-play")], EFTogglePlay);

//#endregion
export { EFTogglePlay };
//# sourceMappingURL=EFTogglePlay.js.map