package com.autonomy.abc.selenium.keywords;

import com.autonomy.abc.selenium.actions.wizard.OptionWizardStep;
import com.autonomy.abc.selenium.actions.wizard.Wizard;
import com.autonomy.abc.selenium.actions.wizard.WizardStep;
import com.autonomy.abc.selenium.page.keywords.CreateNewKeywordsPage;

class KeywordGroup {
    private String keywordString;
    private KeywordType type;

    public KeywordGroup(KeywordType type, String... keywords) {
        this.keywordString = String.join(" ", keywords);
        this.type = type;
    }

    public Wizard makeWizard(CreateNewKeywordsPage newKeywordsPage) {
        return new KeywordWizard(newKeywordsPage);
    }

    private class KeywordWizard extends Wizard {
        private CreateNewKeywordsPage page;

        private KeywordWizard(CreateNewKeywordsPage newKeywordsPage) {
            page = newKeywordsPage;
            buildSteps();
        }

        private void buildSteps() {
            this.add(new OptionWizardStep(page, "Select Type of Keywords", type.getOption()));
            this.add(new WizardStep() {
                @Override
                public String getTitle() {
                    return type.getInputTitle();
                }

                @Override
                public Object apply() {
                    page.loadOrFadeWait();
                    page.addKeywordsInput().setAndSubmit(keywordString);
                    return null;
                }
            });
        }

        @Override
        public void next() {
            if (onFinalStep()) {
                page.finishWizardButton().click();
            } else {
                page.continueWizardButton().click();
                incrementStep();
            }
            page.loadOrFadeWait();
        }

        @Override
        public void cancel() {
            page.cancelWizardButton().click();
        }
    }

}

@@ -289,16 +289,64 @@
 rdsPage;
+%0Aimport com.autonomy.abc.selenium.util.Language;
 %0A%0Aclass 
@@ -423,16 +423,47 @@
 pe type;
+%0A    private Language language;
 %0A%0A    pu
@@ -497,16 +497,35 @@
 pe type,
+ Language language,
  String.
@@ -618,24 +618,58 @@
 ype = type;%0A
+        this.language = language;%0A
     %7D%0A%0A    p
@@ -1094,74 +1094,21 @@
 new 
-OptionWizardStep(page, %22Select Type of Keywords%22, type.getOption()
+TypeStep(page
 ));%0A
@@ -1136,22 +1136,25 @@
 new 
-WizardStep() %7B
+InputStep(page));
 %0A   
@@ -1150,32 +1150,35 @@
 page));%0A        
+%7D%0A%0A
         @Overrid
@@ -1191,88 +1191,109 @@
     
- 
-       public String getTitle() %7B%0A                    return type.getInputTitle
+public void next() %7B%0A            if (onFinalStep()) %7B%0A                page.finishWizardButton().click
 ();%0A
@@ -1300,30 +1300,32 @@
             
-    %7D%0A
+%7D else %7B
 %0A           
@@ -1333,57 +1333,77 @@
     
-@Override%0A                public Object apply() %7B
+page.continueWizardButton().click();%0A                incrementStep();
 %0A   
@@ -1399,32 +1399,38 @@
 Step();%0A        
+    %7D%0A
             page
@@ -1460,138 +1460,390 @@
     
-            page.addKeywordsInput().setAndSubmit(keywordString);%0A                    return null;%0A                %7D%0A            %7D)
+%7D%0A%0A        @Override%0A        public void cancel() %7B%0A            page.cancelWizardButton().click();%0A        %7D%0A    %7D%0A%0A    private class TypeStep extends OptionWizardStep %7B%0A        private CreateNewKeywordsPage page;%0A%0A        public TypeStep(CreateNewKeywordsPage container) %7B%0A            super(container, %22Select Type of Keywords%22, type.getOption());%0A            this.page = container
 ;%0A  
@@ -1880,33 +1880,36 @@
      public 
-void next
+Object apply
 () %7B%0A       
@@ -1917,77 +1917,74 @@
     
-if (onFinalStep()) %7B%0A                page.finishWizardButton().click(
+super.apply();%0A            page.selectLanguage(language.toString()
 );%0A 
@@ -1990,32 +1990,36 @@
             
-%7D else %7B
+return null;
 %0A           
@@ -2019,131 +2019,310 @@
     
+%7D%0A
     
+%7D%0A%0A
     p
-age.continueWizardButton().click();%0A                incrementStep();%0A            %7D%0A            page.loadOrFadeWait
+rivate class InputStep implements WizardStep %7B%0A        private CreateNewKeywordsPage page;%0A%0A        public InputStep(CreateNewKeywordsPage container) %7B%0A            this.page = container;%0A        %7D%0A%0A        @Override%0A        public String getTitle() %7B%0A            return type.getInputTitle
 ();%0A
@@ -2361,35 +2361,36 @@
      public 
-void cancel
+Object apply
 () %7B%0A       
@@ -2403,36 +2403,79 @@
 age.
-cancelWizardButton().click()
+addKeywordsInput().setAndSubmit(keywordString);%0A            return null
 ;%0A  

Add language support for keyword wizard