/*
 * Copyright 2016 Cognifide Ltd..
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cognifide.qa.bb.aem.touch.pageobjects.touchui.dialogfields.text;

import com.cognifide.qa.bb.aem.touch.data.componentconfigs.FieldType;
import com.cognifide.qa.bb.aem.touch.pageobjects.touchui.dialogfields.DialogField;
import com.cognifide.qa.bb.constants.Timeouts;
import com.cognifide.qa.bb.provider.selenium.BobcatWait;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.google.inject.Inject;

import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedCondition;

/**
 * Represents list formatting dialog panel.
 */
@PageObject
public class ListDialogPanel implements DialogField {

  @FindBy(css = ".coral-RichText-toolbar")
  private ControlToolbar controlToolbar;

  @FindBy(css = ".coral-Popover-content")
  private ListControls listControl;

  @Inject
  private BobcatWait bobcatWait;

  /**
   * Performs one of list formatting actions depending on passed parameter value:
   * <ul>
   * <li>NUMBER</li>
   * <li>BULLET</li>
   * <li>INDENT</li>
   * <li>OUTDENT</li>
   * </ul>
   *
   * @param value string value representing desired action.
   */
  @Override
  public void setValue(Object value) {
    String actionText = (String) value;
    ListPanelActions action = ListPanelActions.valueOf(actionText.toUpperCase());

    switch (action) {
      case NUMBERED:
        openListPopover();
        listControl.getNumberListBtn().click();
        break;
      case BULLET:
        openListPopover();
        listControl.getBulletListBtn().click();
        break;
      case INDENT:
        openListPopover();
        listControl.getIndentListBtn().click();
        break;
      case OUTDENT:
        openListPopover();
        listControl.getOutdentListBtn().click();
        break;
      default:
        throw new IllegalArgumentException("There is no action defined for " + actionText);
    }
  }

  private void openListPopover() {
    controlToolbar.selectText();
    bobcatWait.withTimeout(Timeouts.SMALL).until((ExpectedCondition<Object>) input -> controlToolbar.
            getToggleListButton().isEnabled());
    controlToolbar.getToggleListButton().click();
  }

  /**
   * @return dialog field type.
   */
  @Override
  public String getType() {
    return FieldType.RICHTEXT_LIST.name();
  }

  private enum ListPanelActions {
    NUMBERED,
    BULLET,
    INDENT,
    OUTDENT
  }

}

@@ -667,24 +667,125 @@
 elds.text;%0A%0A
+import org.openqa.selenium.support.FindBy;%0Aimport org.openqa.selenium.support.ui.ExpectedCondition;%0A%0A
 import com.c
@@ -842,16 +842,16 @@
 ldType;%0A
-
 import c
@@ -1116,109 +1116,8 @@
 t;%0A%0A
-import org.openqa.selenium.support.FindBy;%0Aimport org.openqa.selenium.support.ui.ExpectedCondition;%0A%0A
 /**%0A
@@ -1316,16 +1316,16 @@
 olbar;%0A%0A
-
   @FindB
@@ -1329,24 +1329,59 @@
 ndBy(css = %22
+div.coral-Popover%5Bdata-id='lists'%5D 
 .coral-Popov
@@ -2603,16 +2603,25 @@
 s.SMALL)
+%0A        
 .until((

Add richText component support to AEM 62