import { hideControl, startConversation } from 'Actions/actions'
import withLanguage from 'Components/utils/withLanguage'
import { makeJsx } from 'Engine/evaluation'
import { createMarkdownDiv } from 'Engine/marked'
import { compose } from 'ramda'
import React from 'react'
import emoji from 'react-easy-emoji'
import { connect } from 'react-redux'
import './Controls.css'
import withColours from './utils/withColours'
function Controls({
controls,
startConversation,
hideControl,
foldedSteps,
colours,
hiddenControls
}) {
if (!controls?.length) return null
return (
{controls.map(({ level, test, message, solution, evaluated }) =>
hiddenControls.includes(test) ? null : (
-
{emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
{message && createMarkdownDiv(message)}
{!message && (
{makeJsx(evaluated)}
)}
{solution && !foldedSteps.includes(solution.cible) && (
{/*emoji('💡')*/}
)}
)
)}
)
}
export default compose(
connect(
(state, props) => ({
foldedSteps: state.conversationSteps.foldedSteps,
key: props.language,
hiddenControls: state.hiddenControls
}),
dispatch => ({
startConversation: cible => dispatch(startConversation(cible)),
hideControl: id => dispatch(hideControl(id))
})
),
withColours,
withLanguage
)(Controls)