/*
 * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
 *
 * 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 org.jboss.hal.client.management;

import org.jboss.gwt.elemento.core.Elements;
import org.jboss.hal.ballroom.Alert;
import org.jboss.hal.core.extension.ExtensionRegistry;
import org.jboss.hal.core.extension.InstalledExtension;
import org.jboss.hal.core.finder.PreviewAttributes;
import org.jboss.hal.core.finder.PreviewContent;
import org.jboss.hal.resources.Icons;
import org.jboss.hal.resources.Names;
import org.jboss.hal.resources.Resources;

import static java.util.Arrays.asList;
import static org.jboss.hal.dmr.ModelDescriptionConstants.*;

class ExtensionPreview extends PreviewContent<InstalledExtension> {

    ExtensionPreview(final InstalledExtension extension,
            final ExtensionRegistry extensionRegistry,
            final Resources resources) {

        super(Names.EXTENSION);

        Alert scriptOk = new Alert(Icons.OK, resources.messages().extensionOk());
        Alert scriptError = new Alert(Icons.ERROR, resources.messages().extensionScriptError());

        PreviewAttributes<InstalledExtension> attributes = new PreviewAttributes<>(extension,
                asList(NAME, VERSION, DESCRIPTION, URL, SCRIPT, STYLESHEETS, EXTENSION_POINT, AUTHOR, HOMEPAGE,
                        LICENSE));

        previewBuilder()
                .add(scriptOk)
                .add(scriptError)
                .addAll(attributes);

        boolean injected = extensionRegistry.verifyScript(extension.getFqScript());
        Elements.setVisible(scriptOk.asElement(), injected);
        Elements.setVisible(scriptError.asElement(), !injected);
    }
}

@@ -744,16 +744,60 @@
 .Alert;%0A
+import org.jboss.hal.ballroom.LabelBuilder;%0A
 import o
@@ -843,16 +843,16 @@
 gistry;%0A
-
 import o
@@ -947,24 +947,93 @@
 Attributes;%0A
+import org.jboss.hal.core.finder.PreviewAttributes.PreviewAttribute;%0A
 import org.j
@@ -1107,16 +1107,52 @@
 .Icons;%0A
+import org.jboss.hal.resources.Ids;%0A
 import o
@@ -1908,103 +1908,639 @@
 TION
-, URL, SCRIPT, STYLESHEETS, EXTENSION_POINT, AUTHOR, HOMEPAGE,%0A                        
+))%0A                .append(model -%3E new PreviewAttribute(Names.URL, model.get(URL).asString(), model.get(URL).asString(),%0A                        Ids.build(model.getName(), URL)))%0A                .append(SCRIPT)%0A                .append(STYLESHEETS)%0A                .append(EXTENSION_POINT)%0A                .append(AUTHOR)%0A                .append(AUTHOR)%0A                .append(model -%3E new PreviewAttribute(new LabelBuilder().label(HOMEPAGE),%0A                        model.get(HOMEPAGE).asString(), model.get(HOMEPAGE).asString(),%0A                        Ids.build(model.getName(), Ids.HOMEPAGE)))%0A                .append(
 LICENSE)
 );%0A%0A
@@ -2535,17 +2535,16 @@
 LICENSE)
-)
 ;%0A%0A     

Add links to extension preview