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

import com.atlassian.soy.renderer.JsExpression;
import com.atlassian.soy.renderer.SoyClientFunction;
import com.google.common.collect.ImmutableSet;

import java.util.Set;

public class HighlightTextFunction implements SoyClientFunction {

    private static final Set<Integer> VALID_ARG_SIZES = ImmutableSet.of(2, 3);

    @Override
    public JsExpression generate(JsExpression... jsExpressions) {
        StringBuilder sb = new StringBuilder();
        sb.append("require('bitbucket/internal/util/highlight-text').highlight(")
            .append(jsExpressions[0].getText()).append(", ")
            .append(jsExpressions[1].getText());
        if (jsExpressions.length > 2) {
            sb.append(", ").append(jsExpressions[2].getText());
        }
        sb.append(")");
        return new JsExpression(sb.toString());
    }

    @Override
    public String getName() {
        return "highlight";
    }

    @Override
    public Set<Integer> validArgSizes() {
        return VALID_ARG_SIZES;
    }
}
