function [modelHyperlink, matlabCmd, tooltipStr] = profGetMatlabCmd(section, simComp, lReportFcn, noteHtml, showFunctionName)
%profGetMatlabCmd generates the Matlab link to highlight models from the
%profiling report

% Copyright 2016-2022 The MathWorks, Inc.

traceInfo = section.getTraceInfo;
isTask = traceInfo.isTask;
codeSection = '';

if isTask
[modelText, entitiesToHighlight] = feval(...
sprintf('%s.getTaskTextandEntity', lReportFcn), traceInfo, simComp);
tooltipStr = entitiesToHighlight{1};
else
lName = getName(traceInfo);
tooltipStr = getTooltip(traceInfo);

if showFunctionName
codeSection = traceInfo.getCodeSectionName;
codeSection = coder.profile.htmlEscape(codeSection);
end

% Escape characters for html
tagFormatted = coder.profile.htmlEscape(lName);
tooltipStr = coder.profile.htmlEscape(tooltipStr);

modelText = tagFormatted;

entitiesToHighlight = getCallSiteSids(traceInfo);
end

matlabCmd = '';
if ~any(strcmp(entitiesToHighlight,''))
highlightArgsStr='';

for i=1:length(entitiesToHighlight)
% Filter invalid SIDs (g828718); for non-task sections we expect to get an SID,
% however, we cannot currently handle extended SIDs
entityToHighlight=entitiesToHighlight{i};
highlightArgsStr = sprintf('%s, ''%s''', highlightArgsStr,...
entityToHighlight);
end

if ~isempty(highlightArgsStr)
highlightArgsStr = highlightArgsStr(3:end); % remove leading comma
matlabCmd = sprintf(...
'%s.modelHighlight(%s);',...
lReportFcn, highlightArgsStr);
end
end
modelHyperlink = coder.profile.ExecTimeHelper.formattedHtml...
(modelText, matlabCmd, tooltipStr, noteHtml, codeSection);
end