//Dependencies
import { loadSettingsConfig } from './config.mjs'
// Hooks
import { useContext } from 'react'
import { useTranslation } from 'next-i18next'
// Context
import { ModalContext } from 'shared/context/modal-context.mjs'
// Components
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
import { Collapse } from 'shared/components/collapse.mjs'
import { HelpIcon, DesktopIcon, ClearIcon } from 'shared/components/icons.mjs'
import { ControlSettingInput, RendererSettingInput } from './inputs.mjs'
import { ControlSettingValue, RendererSettingValue } from './values.mjs'
//import { ConsoleLog } from './log.mjs'
//import { XrayReset } from './reset.mjs'
//import { XrayList } from './list.mjs'
export const ns = ['ui-settings']
// Facilitate lookup of the value component
const values = {
control: ControlSettingValue,
renderer: RendererSettingValue,
//xray: XRaySettingValue,
}
// Facilitate lookup of the input component
const inputs = {
control: ControlSettingInput,
renderer: RendererSettingInput,
//xray: XRaySettingInput,
}
const wasChanged = (current, name, settingsConfig) => {
if (typeof current === 'undefined') return false
if (current === settingsConfig[name].dflt) return false
return true
}
export const UiTitle = ({ name, t, current = null, open = false, emoji = '' }) => (
{emoji}
{t(`ui-settings:${name}.t`)}
{open ? ':' : ''}
{current}
)
export const Setting = ({ name, config, current, update, t, changed, loadDocs, control, ui }) => {
const drillProps = { name, config, current, update, t, changed, control }
// Don't bother with X-Ray in SVG mode
if (name === 'xray' && ui.renderer === 'svg') return null
const Input = inputs[name]
const Value = values[name]
const buttons = []
const openButtons = []
if (loadDocs)
openButtons.push(
)
if (changed) {
buttons.push(
)
openButtons.push(
)
}
const titleProps = { name, t, current: , emoji: config.emoji }
if (control > 4) {
// Save gurus some clicks
if (name === 'renderer')
return (
}
onClick={() => (current === 'svg' ? update.ui([name]) : update.ui([name], 'svg'))}
/>
)
}
return (
}
title={}
buttons={buttons}
openButtons={openButtons}
>
)
}
export const UiSettings = ({ design, update, settings, ui, control, language, DynamicDocs }) => {
const { t } = useTranslation(ns)
const { setModal } = useContext(ModalContext)
const settingsConfig = loadSettingsConfig()
const loadDocs = DynamicDocs
? (evt, setting = false) => {
evt.stopPropagation()
let path = `site/draft/ui-settings`
if (setting) path += `/${setting}`
setModal(
)
}
: false
return (
<>
{control > 4 ? (
) : (
<>
{t('ui-settings:uiSettings')}
{t('ui-settings:uiSettings.d')}
>
)}
{Object.keys(settingsConfig)
.filter((name) => settingsConfig[name].control <= control)
.map((name) => (
))}
>
)
}