// __SDEFILE__ - This file is a dependency for the stand-alone environment
import { useTranslation } from 'next-i18next'
import { analyzeDraftLogLine } from './errors.mjs'
import { Mdx } from 'shared/components/mdx/dynamic.mjs'
import { ns as coreMenuNs } from 'shared/components/workbench/menus/core-settings/index.mjs'
export const ns = ['logs', ...coreMenuNs]
const colors = {
error: 'error',
warn: 'warning',
info: 'secondary',
debug: 'base',
}
const DraftLogEntry = ({ type, line, t }) => {
// Some lines are arrays, handle each entry individually
if (Array.isArray(line))
return line.reverse().map((l, key) => )
let title = 'Unsure how to treat this error'
const data = []
// Simple error string
if (typeof line === 'string') title = line
if (typeof line === 'object') {
data.push(analyzeDraftLogLine({ type, line, t }))
title = line.toString()
}
return (
)
}
const DraftLogs = ({ type, t, lines = [] }) =>
lines.length > 0 ? (
<>
{t(type)}
{lines.reverse().map((line, key) => (
))}
>
) : null
const extractLogs = (pattern) => {
const logs = {}
for (const type of ['error', 'warn', 'info', 'debug']) {
logs[type] = [...pattern.store.logs[type]]
for (const store of pattern.setStores) logs[type].push(...store.logs[type])
}
return logs
}
export const LogView = ({ pattern, settings, setSettings }) => {
const { t } = useTranslation(ns)
try {
pattern.draft(settings)
} catch (err) {
console.log(err)
}
const logs = extractLogs(pattern)
return (
{t('logs')}
{Object.entries(logs).map(([type, lines], key) => (
))}
)
}