/**
 * Copyright (c) 2015-present, Horcrux.
 * All rights reserved.
 *
 * This source code is licensed under the MIT-style license found in the
 * LICENSE file in the root directory of this source tree.
 */


package com.horcrux.svg;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.ThemedReactContext;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

/**
 * ViewManager for RNSVGSvgView React views. Renders as a {@link RNSVGSvgView} and handles
 * invalidating the native view on shadow view updates happening in the underlying tree.
 */
public class RNSVGSvgViewManager extends BaseViewManager<RNSVGSvgView, RNSVGSvgViewShadowNode> {

    private static final String REACT_CLASS = "RNSVGSvgView";
    private static final int COMMAND_TO_DATA_URL = 100;

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    public @Nullable Map<String, Integer> getCommandsMap() {
        Map<String, Integer> commandsMap = super.getCommandsMap();
        if (commandsMap == null) {
            commandsMap = new HashMap<>();
        }

        commandsMap.put("toDataURL", COMMAND_TO_DATA_URL);
        return commandsMap;
    }

    @Override
    @Nullable
    public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
        MapBuilder.Builder<String, Object> builder = MapBuilder.builder();

        for (RNSVGSvgView.Events event : RNSVGSvgView.Events.values()) {
            builder.put(event.toString(), MapBuilder.of("registrationName", event.toString()));
        }
        return builder.build();
    }

    @Override
    public void receiveCommand(RNSVGSvgView root, int commandId, @Nullable ReadableArray args) {
        super.receiveCommand(root, commandId, args);

        switch (commandId) {
            case COMMAND_TO_DATA_URL:
                root.onDataURL();
                break;
        }
    }

    @Override
    public Class<RNSVGSvgViewShadowNode> getShadowNodeClass() {
        return RNSVGSvgViewShadowNode.class;
    }

    @Override
    public RNSVGSvgViewShadowNode createShadowNodeInstance() {
        return new RNSVGSvgViewShadowNode();
    }

    @Override
    protected RNSVGSvgView createViewInstance(ThemedReactContext reactContext) {
        return new RNSVGSvgView(reactContext);
    }

    @Override
    public void updateExtraData(RNSVGSvgView root, Object extraData) {
        root.setSurfaceTextureListener((RNSVGSvgViewShadowNode) extraData);
    }
}

@@ -991,32 +991,608 @@
 T_CLASS;%0A    %7D%0A%0A
+    @Override%0A    public Class%3CRNSVGSvgViewShadowNode%3E getShadowNodeClass() %7B%0A        return RNSVGSvgViewShadowNode.class;%0A    %7D%0A%0A    @Override%0A    public RNSVGSvgViewShadowNode createShadowNodeInstance() %7B%0A        return new RNSVGSvgViewShadowNode();%0A    %7D%0A%0A    @Override%0A    protected RNSVGSvgView createViewInstance(ThemedReactContext reactContext) %7B%0A        return new RNSVGSvgView(reactContext);%0A    %7D%0A%0A    @Override%0A    public void updateExtraData(RNSVGSvgView root, Object extraData) %7B%0A        root.setSurfaceTextureListener((RNSVGSvgViewShadowNode) extraData);%0A    %7D%0A%0A
     @Override%0A  
@@ -2607,583 +2607,7 @@
    %7D
-%0A%0A    @Override%0A    public Class%3CRNSVGSvgViewShadowNode%3E getShadowNodeClass() %7B%0A        return RNSVGSvgViewShadowNode.class;%0A    %7D%0A%0A    @Override%0A    public RNSVGSvgViewShadowNode createShadowNodeInstance() %7B%0A        return new RNSVGSvgViewShadowNode();%0A    %7D%0A%0A    @Override%0A    protected RNSVGSvgView createViewInstance(ThemedReactContext reactContext) %7B%0A        return new RNSVGSvgView(reactContext);%0A    %7D%0A%0A    @Override%0A    public void updateExtraData(RNSVGSvgView root, Object extraData) %7B%0A        root.setSurfaceTextureListener((RNSVGSvgViewShadowNode) extraData);%0A    %7D
 %0A%7D%0A

remove commands related code to the bottom