import type { SettingsField } from '@/types/settings.types' // Same rule as wc_string_to_bool(). export const toBool = (value: unknown): boolean => { if (typeof value === 'boolean') { return value } if (value === 1 || value === '1') { return true } if (typeof value === 'string') { const lower = value.toLowerCase() return lower === 'yes' || lower === 'true' } return false } // Mirror of Save::is_visible(): every show_if entry must match the page state. export const isVisible = ( field: SettingsField, fieldsById: Record, state: Record ): boolean => { return Object.entries(field.show_if ?? {}).every(([parent, expected]) => { const actual = state[parent] ?? null if (fieldsById[parent]?.type === 'checkbox') { return toBool(actual) === Boolean(expected) } return String(actual ?? '') === String(expected ?? '') }) }