// Settings pages the admin may manage (D-21), server-filtered like the // navigation. The rail shows "Ustawienia" only when this list is non-empty. import { computed, readonly, ref } from 'vue' import { api } from '../api/client' import type { SettingsEntry } from '../api/types' const entries = ref([]) export const settings = readonly(entries) export const hasSettings = computed(() => entries.value.length > 0) export async function loadSettings(): Promise { const { data, response } = await api.GET('/settings') entries.value = response.ok && data ? data.data : [] return entries.value } export function setSettings(next: SettingsEntry[]): void { entries.value = next } export function settingsEntry(code: string): SettingsEntry | null { return entries.value.find((entry) => entry.code === code) ?? null } /** Entries grouped by category, categories in first-seen order, by order. */ export const settingsGroups = computed(() => { const sorted = entries.value .map((entry, index) => ({ entry, index })) .sort((a, b) => a.entry.order - b.entry.order || a.index - b.index) .map(({ entry }) => entry) const groups: Array<{ category: string; entries: SettingsEntry[] }> = [] for (const entry of sorted) { let group = groups.find((item) => item.category === entry.category) if (!group) { group = { category: entry.category, entries: [] } groups.push(group) } group.entries.push(entry) } return groups }) export function useSettings() { return { settings, hasSettings, settingsGroups, loadSettings, settingsEntry } }