package com.cloudera.server.web.cmf.wizard.service;

import com.cloudera.cmf.model.DbService;
import com.cloudera.enterprise.JsonUtil2;
import com.cloudera.server.web.cmf.WizardBaseImpl;
import com.cloudera.server.web.cmf.wizard.CommandDetailsStep;
import com.cloudera.server.web.cmf.wizard.WizardButtons;
import com.cloudera.server.web.cmf.wizard.WizardHiddenStepBase;
import com.cloudera.server.web.cmf.wizard.common.SimpleTextStep;
import com.cloudera.server.web.common.I18n;
import com.cloudera.server.web.common.Util;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import org.jamon.TemplateManager;
import org.jamon.emit.StandardEmitter;
import org.jamon.escaping.Escaping;

public class DisableRMWizardPageImpl extends WizardBaseImpl
  implements DisableRMWizardPage.Intf
{
  private final DbService service;
  private final String returnUrl;
  private final HAWizardOptions jsOptions;
  private final String roleType;

  protected static DisableRMWizardPage.ImplData __jamon_setOptionalArguments(DisableRMWizardPage.ImplData p_implData)
  {
    WizardBaseImpl.__jamon_setOptionalArguments(p_implData);
    return p_implData;
  }

  public DisableRMWizardPageImpl(TemplateManager p_templateManager, DisableRMWizardPage.ImplData p_implData) {
    super(p_templateManager, __jamon_setOptionalArguments(p_implData));
    this.service = p_implData.getService();
    this.returnUrl = p_implData.getReturnUrl();
    this.jsOptions = p_implData.getJsOptions();
    this.roleType = p_implData.getRoleType();
  }

  protected void child_render_3(Writer jamonWriter)
    throws IOException
  {
    List stepIds = ImmutableList.of("gettingStartedStep", "commandStep", "commandDetailsStep");

    Iterator stepIdIterator = stepIds.iterator();

    jamonWriter.write("<div class=\"Wizard container\">\n    <h1>");

    Escaping.HTML.write(StandardEmitter.valueOf(I18n.t("message.disableIntegratedRM.title", new String[] { this.service.getDisplayName() })), jamonWriter);

    jamonWriter.write("</h1>\n\n    <div id=\"");

    Escaping.STRICT_HTML.write(StandardEmitter.valueOf((String)stepIdIterator.next()), jamonWriter);

    jamonWriter.write("\">\n        ");

    SimpleTextStep __jamon__var_765 = new SimpleTextStep(getTemplateManager());
    __jamon__var_765.renderNoFlush(jamonWriter, I18n.t("label.gettingStarted"), I18n.t("message.disableIntegratedRM.generic.desc", new String[] { this.service.getDisplayName() }));

    jamonWriter.write("\n    </div>\n\n    <div id=\"");

    Escaping.STRICT_HTML.write(StandardEmitter.valueOf((String)stepIdIterator.next()), jamonWriter);

    jamonWriter.write("\">\n        ");

    WizardHiddenStepBase __jamon__var_766 = new WizardHiddenStepBase(getTemplateManager());
    __jamon__var_766.renderNoFlush(jamonWriter);

    jamonWriter.write("\n    </div>\n\n    <div id=\"");

    Escaping.STRICT_HTML.write(StandardEmitter.valueOf((String)stepIdIterator.next()), jamonWriter);

    jamonWriter.write("\">\n        ");

    CommandDetailsStep __jamon__var_767 = new CommandDetailsStep(getTemplateManager());
    __jamon__var_767.renderNoFlush(jamonWriter);

    jamonWriter.write("\n    </div>\n</div>\n\n");

    WizardButtons __jamon__var_768 = new WizardButtons(getTemplateManager());
    __jamon__var_768.renderNoFlush(jamonWriter);

    jamonWriter.write("\n\n<script type=\"text/javascript\">\nrequire([\n    \"cloudera/cmf/wizard/service/DisableRMWizard\"\n], function(DisableRMWizard) {\n    jQuery(function($) {\n      var jsOptions = ");

    Escaping.NONE.write(StandardEmitter.valueOf(JsonUtil2.valueAsString(this.jsOptions)), jamonWriter);

    jamonWriter.write(";\n      var options = $.extend(jsOptions, {\n        container: \"#bottomButtons\",\n        stepIds: ");

    Escaping.NONE.write(StandardEmitter.valueOf(JsonUtil2.valueAsString(stepIds)), jamonWriter);

    jamonWriter.write(",\n        exitUrl: \"");

    Escaping.JAVASCRIPT.write(StandardEmitter.valueOf(Util.escapeForJS(this.returnUrl)), jamonWriter);

    jamonWriter.write("\"\n      });\n      var page = new DisableRMWizard(options);\n    });\n});\n</script>\n");
  }
}