'use strict';

goog.provide('Blockly.Python.if');

goog.require('Blockly.Python');

Blockly.Python['controls_if_better'] = function(block) {
    // If/elseif/else condition.
    var n = 0;
    var code = '', branchCode, conditionCode;
    do {
      conditionCode = Blockly.Python.valueToCode(block, 'IF' + n,
        Blockly.Python.ORDER_NONE) || '___';
      branchCode = Blockly.Python.statementToCode(block, 'DO' + n) ||
          Blockly.Python.PASS;
      code += (n == 0 ? 'if ' : 'elif ' ) + conditionCode + ':\n' + branchCode;
  
      ++n;
    } while (block.getInput('IF' + n));
  
    if (block.getInput('ELSE')) {
      branchCode = Blockly.Python.statementToCode(block, 'ELSE') ||
          Blockly.Python.PASS;
      code += 'else:\n' + branchCode;
    }
    return code;
  };