import { Component, ChangeDetectionStrategy, input, output, inject, effect } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GraphConfig } from '../graph-settings.types';
import { GraphSettingsService } from '../graph-settings.service';
import { GraphSettingsAccordionComponent } from '../../../components/graph-settings/graph-settings-accordion.component';
@Component({
selector: 'app-graph-settings-panel',
standalone: true,
imports: [
CommonModule,
GraphSettingsAccordionComponent
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
`,
styles: [`
.settings-panel {
position: fixed;
inset: 0;
z-index: 2000;
pointer-events: none;
}
.backdrop {
position: fixed;
inset: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1990;
pointer-events: auto;
}
.panel-content {
position: fixed;
top: 0;
right: 0;
bottom: 0;
width: 100%;
max-width: 400px;
background-color: white;
box-shadow: -4px 0 6px -1px rgba(0, 0, 0, 0.1), -2px 0 4px -1px rgba(0, 0, 0, 0.06);
display: flex;
flex-direction: column;
z-index: 2001;
transform: translateX(0);
pointer-events: auto;
}
:host-context(.dark) .panel-content {
background-color: #1F2937;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem 1.5rem;
border-bottom: 1px solid #E5E7EB;
}
:host-context(.dark) .panel-header {
border-bottom-color: #374151;
}
.panel-body {
flex: 1;
overflow-y: auto;
padding: 1rem;
}
@media (max-width: 768px) {
.panel-content {
max-width: 100%;
}
}
`]
})
export class GraphSettingsPanelComponent {
isOpen = input.required();
close = output();
animateRequested = output();
private settingsService = inject(GraphSettingsService);
config = this.settingsService.config;
constructor() {
// Listen to Escape key globally when panel is open
effect(() => {
if (!this.isOpen()) {
return;
}
const handler = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
this.close.emit();
}
};
document.addEventListener('keydown', handler);
return () => document.removeEventListener('keydown', handler);
});
}
onConfigChange(patch: Partial): void {
this.settingsService.save(patch);
}
onResetAll(): void {
if (confirm('Reset all graph settings to defaults?')) {
this.settingsService.resetToDefaults();
}
}
}