// Settings → General (plan step 6.14a; was the v1 AppInfoTab): the system (version and whether an
// update is out, license, running or locked, how long it has been up), the local network the
// phones use (the server's address, changed by hand or found by itself; the pairing QR), what the
// venue has set up, exporting / importing the catalogue and the tables, and the support account's
// lock / unlock. The time zone is in "Venue & language" (it was here twice).
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { Lock, LockOpen, QrCode as QrIcon, RefreshCw } from 'lucide-react'
import { useAccess } from '@xenia/access'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Columns, Dialog, Input, Spinner } from '@xenia/ui'
import { QrCode } from '@xenia/ui/qr'
import client from '../../../api/client'
import { useLiveQuery } from '../../../live/useLiveQuery'
import { Pill } from '../../overview/parts'
import DataTransfer from './DataTransfer'
import { SettingRow, SettingsCard } from './SettingsCard'
import { lanAddress, uptime, waiterPairUrl } from './settingsLogic'
export default function SystemSettings() {
const { t } = useTranslation('manager')
const fmt = useFormat()
const qc = useQueryClient()
const { user } = useAccess()
const [qr, setQr] = useState(null)
const { data: status, isPending } = useLiveQuery({ queryKey: ['system-status'], queryFn: () => client.get('/api/system/status').then(r => r.data), refetchInterval: 30_000 })
const { data: stats } = useLiveQuery({ queryKey: ['system-stats'], queryFn: () => client.get('/api/system/stats').then(r => r.data), staleTime: 60_000 })
const refresh = useMutation({
mutationFn: () => client.post('/api/system/sync-license').catch(() => null), // the cloud may be away: still refresh what we know
onSettled: () => { qc.invalidateQueries({ queryKey: ['system-status'] }); qc.invalidateQueries({ queryKey: ['license-status'] }) },
})
const lock = useMutation({
mutationFn: on => client.post(on ? '/api/system/lock' : '/api/system/unlock'),
onSuccess: (_r, on) => { toast.success(t(on ? 'settings.system.locked' : 'settings.system.unlocked')); qc.invalidateQueries({ queryKey: ['system-status'] }) },
onError: err => toast.error(errorMessage(err, t)),
})
if (isPending) return