package com.atlassian.stash.internal.web.soy.functions.nav;

import com.atlassian.stash.internal.web.soy.functions.SoyArgumentUtils;
import com.atlassian.bitbucket.nav.NavBuilder;
import com.atlassian.soy.renderer.JsExpression;

public class AdminGroupListNavFunction extends BaseNavFunction {

    public AdminGroupListNavFunction(NavBuilder navBuilder) {
        super(navBuilder, "nav_admin_groups", 0, 1);
    }

    @Override
    protected JsNavBuilder initJsBuilder(JsExpression... jsExpressions) {
        if (jsExpressions.length == 0) {
            return new JsNavBuilder().admin().groups();
        } else {
            return new JsNavBuilder().admin().groups().callMethod("filter", jsExpressions[0]);
        }
    }

    @Override
    protected NavBuilder.Builder initBuilder(Object... args) {
        if (args.length == 0) {
            return navBuilder.admin().groups();
        } else  {
            return navBuilder.admin().groups().filter(SoyArgumentUtils.getStringArgument(args, 0));
        }
    }

}
