/**
* ds-admin-settings.js
* Admin settings panel for DSS configuration
* Allows configuration of hostname, port, and local/remote setup
*/
import { useAdminStore } from '../../stores/admin-store.js';
export default class AdminSettings extends HTMLElement {
constructor() {
super();
this.adminStore = useAdminStore();
this.state = this.adminStore.getState();
}
connectedCallback() {
this.render();
this.setupEventListeners();
this.unsubscribe = this.adminStore.subscribe(() => {
this.state = this.adminStore.getState();
this.updateUI();
});
}
disconnectedCallback() {
if (this.unsubscribe) this.unsubscribe();
}
render() {
this.innerHTML = `
DSS Settings
CURRENT STORYBOOK URL:
${this.getStorybookUrlDisplay()}
`;
}
setupEventListeners() {
const hostnameInput = this.querySelector('#hostname-input');
const portInput = this.querySelector('#port-input');
const setupTypeRadios = this.querySelectorAll('input[name="setup-type"]');
const saveBtn = this.querySelector('#save-btn');
const resetBtn = this.querySelector('#reset-btn');
// Update on input (but don't save immediately)
hostnameInput.addEventListener('change', () => {
this.adminStore.setHostname(hostnameInput.value);
});
portInput.addEventListener('change', () => {
const port = parseInt(portInput.value);
if (port > 0 && port <= 65535) {
this.adminStore.setPort(port);
}
});
setupTypeRadios.forEach(radio => {
radio.addEventListener('change', (e) => {
this.adminStore.setRemote(e.target.value === 'remote');
});
});
saveBtn.addEventListener('click', () => {
this.showNotification('Settings saved successfully!');
console.log('[AdminSettings] Settings saved:', this.adminStore.getState());
});
resetBtn.addEventListener('click', () => {
if (confirm('Reset all settings to defaults?')) {
this.adminStore.reset();
this.render();
this.setupEventListeners();
this.showNotification('Settings reset to defaults');
}
});
}
updateUI() {
const hostnameInput = this.querySelector('#hostname-input');
const portInput = this.querySelector('#port-input');
const setupTypeRadios = this.querySelectorAll('input[name="setup-type"]');
const urlDisplay = this.querySelector('#storybook-url-display');
if (hostnameInput) hostnameInput.value = this.state.hostname;
if (portInput) portInput.value = this.state.port;
setupTypeRadios.forEach(radio => {
radio.checked = (radio.value === 'remote') === this.state.isRemote;
});
if (urlDisplay) {
urlDisplay.textContent = this.getStorybookUrlDisplay();
}
}
getStorybookUrlDisplay() {
return this.adminStore.getStorybookUrl('default');
}
showNotification(message) {
const notification = document.createElement('div');
notification.textContent = message;
notification.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background: var(--vscode-notifications-background);
color: var(--vscode-foreground);
padding: 12px 16px;
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
z-index: 1000;
animation: slideIn 0.3s ease;
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
}
customElements.define('ds-admin-settings', AdminSettings);