p = 'frontend/src/pages/QuizPage.jsx'
s = open(p).read()

s = s.replace('''                    const showCorrect = marked && isCorrectOpt
                    const showWrong = marked && isSelected && !isCorrectOpt''',
'''                    const showCorrect = marked && isCorrectOpt
                    // Every option that is not the answer is wrong, not only
                    // the one that was picked. Once the answer is on the
                    // screen the learner is reading all four, and a bare row
                    // beside a coloured one reads as "not considered" rather
                    // than "this one is wrong too".
                    const showWrong = marked && !isCorrectOpt
                    // Open the moment the question is revealed. It used to
                    // take a click per option, which is three clicks to read
                    // the thing the screen exists for.
                    const openWhy = marked && !!current.option_explanations?.[opt]''')

s = s.replace('''                        aria-disabled={marked && !current.option_explanations?.[opt]}
                        aria-expanded={marked && current.option_explanations?.[opt]
                          ? (showAllExplanations || openExplanations.has(i)) : undefined}''',
'''                        aria-disabled={marked}''')

s = s.replace('''                        onClick={() => {
                          if (hasActiveTextSelection()) return
                          if (!marked) return chooseAnswer(opt)
                          // Once answered, the option is a disclosure for its
                          // own reasoning: clicking it opens that, and clicking
                          // it again closes it.
                          if (current.option_explanations?.[opt]) toggleOptionExplanation(i)
                        }}''',
'''                        onClick={() => {
                          if (hasActiveTextSelection()) return
                          if (!marked) return chooseAnswer(opt)
                          // Nothing to toggle: everything is already open.
                        }}''')

s = s.replace('''                        style={{
                          cursor: marked && current.option_explanations?.[opt] ? 'pointer' : marked ? 'default' : 'pointer',''',
'''                        style={{
                          cursor: marked ? 'default' : 'pointer',''')

s = s.replace('''                      {marked && (showAllExplanations || openExplanations.has(i)) && current.option_explanations?.[opt] && (''',
'''                      {openWhy && (''')

s = s.replace('''                      <div key={i} className={`option-row${
                        showCorrect ? ' is-correct' : showWrong ? ' is-wrong' : ''}${
                        marked && current.option_explanations?.[opt] ? ' has-why' : ''}`}>''',
'''                      <div key={i} className={`option-row${
                        showCorrect ? ' is-correct' : showWrong ? ' is-wrong' : ''}${
                        openWhy ? ' has-why' : ''}`}>''')

# The toggle is gone: there is nothing left to show or hide.
s = s.replace('''                      {Object.keys(current.option_explanations || {}).length > 0 && (
                        <button type="button" className="quiz-stats-toggle" aria-pressed={showAllExplanations} onClick={() => setShowAllExplanations(v => !v)}>
                          {showAllExplanations ? 'Hide explanations' : 'Show all explanations'}
                        </button>
                      )}
''', '')
open(p, 'w').write(s)
print('written')
