function nnstart(command)
% NNSTART Neural Network Start app
%
%    NNSTART opens the Neural Network Start app.
%
%    NNSTART("close") closes the Neural Network Start app.

% Copyright 2010-2022 The MathWorks, Inc.

if nargin > 0
    command = convertStringsToChars(command);
else
    % No args (expected call) - assume "-v2" flag.
    command = '-v2';
end

try
    nnet.internal.app.common.errorIfPlatformNotSupported;
catch exception
    % Re-throw the error here in order that the error message comes from
    % the nnstart command itself. This results in a friendlier error
    % message, particularly on MATLAB mobile.
    throw(exception)
end

try
    switch command
        case '-v1'
            error(message("nnapp:start:VersionFlagDeprecationError"));
        case '-v2'
            nnet.internal.app.start.openStartApp();
        case {'hide','close'}
            iAttemptToCloseV2App();
        case iUnsupportedAPICommands()
            error(message("nnapp:common:DeprecatedCommand", ...
                "nnstart", string(command)));
        otherwise
            error(message("nnapp:common:UnsupportedCommand", ...
                "nnstart", string(command)));
    end
catch me
    throwAsCaller(me);
end

end

function iAttemptToCloseV2App()
view = getappdata(groot, "SHALLOWNETAPP_STARTAPP");
if ~isempty(view) && isvalid(view)
   view.close(); 
end
end

function commands = iUnsupportedAPICommands()
commands = {'handle', 'tool', 'select'};
end