import { ContextConsumer } from "@videojs/element/context";

//#region src/store/container-mixin.ts
/**
* Create a mixin that consumes player context and registers itself as the
* container element with the provider via `containerContext`.
*
* @param config - Container configuration with player and container contexts.
*/
function createContainerMixin(config) {
	return (BaseClass) => {
		class PlayerContainerElement extends BaseClass {
			#contextStore = null;
			#setContainer = null;
			constructor(...args) {
				super(...args);
				new ContextConsumer(this, {
					context: config.playerContext,
					callback: (value) => {
						this.#contextStore = value ?? null;
					},
					subscribe: true
				});
				new ContextConsumer(this, {
					context: config.containerContext,
					callback: (value) => {
						this.#setContainer = value?.setContainer ?? null;
						if (this.isConnected) this.#setContainer?.(this);
					},
					subscribe: true
				});
			}
			get store() {
				return this.#contextStore;
			}
			connectedCallback() {
				super.connectedCallback();
				this.#setContainer?.(this);
			}
			disconnectedCallback() {
				super.disconnectedCallback();
				this.#setContainer?.(null);
			}
		}
		return PlayerContainerElement;
	};
}

//#endregion
export { createContainerMixin };
//# sourceMappingURL=container-mixin.js.map