class WebRTCStreamerAlgoElement extends HTMLElement {	
	static get observedAttributes() {
		return ['selected'];
	}  	
	constructor() {
		super(); 
		this.shadowDOM = this.attachShadow({mode: 'open'});
		this.shadowDOM.innerHTML = `
					
                    
                        
                    
					`;
	}
	connectedCallback() {
		this.fillList();
	}
	
	attributeChangedCallback(attrName, oldVal, newVal) {
		if (attrName === "selected") {
			this.selected = newVal;
			let mediaList = this.shadowDOM.getElementById("algoList");
			for (const option of mediaList.getElementsByTagName('option')) {
				if (option.value === newVal) {
					option.selected = true;
				}
			}
		}
	}	
	fillList() {
		let algoList = this.shadowDOM.getElementById("algoList");
		algoList.onchange = (event) => {
				this.dispatchEvent(new CustomEvent('change', {
					detail: {
                        algo: algoList.selectedOptions[0].value,
					}
				  }));		
			}
	}
}
customElements.define('webrtc-streamer-algo', WebRTCStreamerAlgoElement);