import React from 'react'
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { useTranslation } from 'react-i18next'
import Icon from '../../../shared/components/icon'
const MAX_ERRORS_COUNT = 99
function PreviewLogsToggleButton({
onToggle,
showLogs,
autoCompileLintingError = false,
compileFailed = false,
logsState: { nErrors, nWarnings },
showText
}) {
const { t } = useTranslation()
let textStyle = {}
let btnColorCssClass = 'btn-default'
let buttonContents
if (!showText) {
textStyle = {
position: 'absolute',
right: '-100vw'
}
}
function handleOnClick(e) {
e.currentTarget.blur()
onToggle()
}
if (showLogs) {
buttonContents =
} else {
buttonContents = (
)
if (autoCompileLintingError || nErrors > 0) {
btnColorCssClass = 'btn-danger'
} else if (nWarnings > 0) {
btnColorCssClass = 'btn-warning'
}
}
const buttonClasses = classNames(
'btn',
'btn-xs',
'btn-toggle-logs',
'toolbar-item',
btnColorCssClass
)
const buttonElement = (
)
return showText ? (
buttonElement
) : (
{showLogs ? t('view_pdf') : t('view_logs')}
}
>
{buttonElement}
)
}
function CompilationResult({
textStyle,
autoCompileLintingError,
nErrors,
nWarnings
}) {
if (autoCompileLintingError) {
return
} else if (nErrors || nWarnings) {
return (
)
} else {
return
}
}
function ViewPdf({ textStyle }) {
const { t } = useTranslation()
return (
<>
{t('view_pdf')}
>
)
}
function LogsCompilationResult({ textStyle, logType, nLogs }) {
const { t } = useTranslation()
const label =
logType === 'errors' ? t('your_project_has_errors') : t('view_warnings')
return (
<>
{`${label} (${
nLogs > MAX_ERRORS_COUNT ? `${MAX_ERRORS_COUNT}+` : nLogs
})`}
>
)
}
function AutoCompileLintingError({ textStyle }) {
const { t } = useTranslation()
return (
<>
{t('code_check_failed')}
>
)
}
function ViewLogs({ textStyle }) {
const { t } = useTranslation()
return (
<>
{t('view_logs')}
>
)
}
PreviewLogsToggleButton.propTypes = {
onToggle: PropTypes.func.isRequired,
logsState: PropTypes.shape({
nErrors: PropTypes.number.isRequired,
nWarnings: PropTypes.number.isRequired
}),
showLogs: PropTypes.bool.isRequired,
showText: PropTypes.bool.isRequired,
compileFailed: PropTypes.bool,
autoCompileLintingError: PropTypes.bool
}
CompilationResult.propTypes = {
textStyle: PropTypes.object.isRequired,
autoCompileLintingError: PropTypes.bool,
nErrors: PropTypes.number.isRequired,
nWarnings: PropTypes.number.isRequired
}
LogsCompilationResult.propTypes = {
logType: PropTypes.string.isRequired,
nLogs: PropTypes.number.isRequired,
textStyle: PropTypes.object.isRequired
}
AutoCompileLintingError.propTypes = {
textStyle: PropTypes.object.isRequired
}
ViewLogs.propTypes = {
textStyle: PropTypes.object.isRequired
}
ViewPdf.propTypes = {
textStyle: PropTypes.object.isRequired
}
export default PreviewLogsToggleButton