class CustomBotControls extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.isRunning = false; } connectedCallback() { this.render(); this.attachEventListeners(); } render() { this.shadowRoot.innerHTML = `

Bot Configuration

Stopped
Double stake after loss to recover previous losses
Risk Warning: Trading involves significant risk. Past performance does not guarantee future results.
`; } attachEventListeners() { const toggleBtn = this.shadowRoot.getElementById('toggle-btn'); const strategySelect = this.shadowRoot.getElementById('strategy'); const strategyDesc = this.shadowRoot.getElementById('strategy-desc'); toggleBtn.addEventListener('click', () => { this.isRunning = !this.isRunning; this.updateButtonState(); // Dispatch event to main script const event = new CustomEvent(this.isRunning ? 'start-bot' : 'stop-bot', { bubbles: true, composed: true }); this.dispatchEvent(event); // Update config this.dispatchConfigChange(); }); strategySelect.addEventListener('change', (e) => { const descriptions = { martingale: 'Double stake after loss to recover previous losses', 'martingale-0.5': 'Increase stake by 50% after loss for gradual recovery', trend: 'Follow the market trend direction', reversal: 'Trade against the current trend', random: 'Random entry points for testing' }; strategyDesc.textContent = descriptions[e.target.value]; this.dispatchConfigChange(); }); // Listen for all input changes this.shadowRoot.querySelectorAll('input, select').forEach(input => { input.addEventListener('change', () => this.dispatchConfigChange()); }); } updateButtonState() { const btn = this.shadowRoot.getElementById('toggle-btn'); const status = this.shadowRoot.getElementById('bot-status'); if (this.isRunning) { btn.className = 'toggle-btn stop-btn'; btn.innerHTML = ` Stop Bot `; status.textContent = 'Running'; status.className = 'status-badge running'; } else { btn.className = 'toggle-btn start-btn'; btn.innerHTML = ` Start Bot `; status.textContent = 'Stopped'; status.className = 'status-badge'; } } dispatchConfigChange() { const config = { strategy: this.shadowRoot.getElementById('strategy').value, stake: this.shadowRoot.getElementById('stake').value, maxStake: this.shadowRoot.getElementById('max-stake').value, duration: this.shadowRoot.getElementById('duration').value, targetProfit: this.shadowRoot.getElementById('target-profit').value, stopLoss: this.shadowRoot.getElementById('stop-loss').value }; const event = new CustomEvent('config-change', { detail: config, bubbles: true, composed: true }); this.dispatchEvent(event); } } customElements.define('custom-bot-controls', CustomBotControls);