package com.braintree.customersupportbackoffice.editor;

import com.hybris.cockpitng.editor.defaultinteger.DefaultIntegerEditor;
import com.hybris.cockpitng.editors.EditorContext;
import com.hybris.cockpitng.editors.EditorListener;
import de.hybris.platform.core.model.BraintreeHostedFieldsConfigurationModel;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.ext.Disable;

public class BrainTreeHostedFieldsConfigurationIntegerEditor extends DefaultIntegerEditor {

    private static final String PARENT_OBJECT = "parentObject";

    @Override
    public void render(Component parent, EditorContext<Integer> context, EditorListener<Integer> listener) {
        callParentRender(parent, context, listener);
        disableConfig(parent, context);
    }

    protected void disableConfig(Component parent, EditorContext<Integer> context) {
        BraintreeHostedFieldsConfigurationModel braintreeHostedFieldsConfigurationModel =
                (BraintreeHostedFieldsConfigurationModel) context.getParameter(PARENT_OBJECT);
        if (!braintreeHostedFieldsConfigurationModel.isEnabled()) {
            Disable disable = (Disable) parent.getFirstChild();
            disable.setDisabled(true);
        }
    }

    protected void callParentRender(Component parent, EditorContext<Integer> context, EditorListener<Integer> listener) { super.render(parent, context, listener); }
}