function optimtool(varargin)
%OPTIMTOOL Optimization Toolbox Graphical User Interface.
%
% Optimtool has been removed. Use the Optimize Live Editor task instead.
%
%   See also OPTIMIZE.

%   Copyright 2006-2023 The MathWorks, Inc.

% Make an "error-dialog-like" dialog that can launch
% the Optimize Live Editor Task template script if desired.

% If an existing uifigure with the same name and tag id exists, exit function
name = getString(message('optim:optimtool:TitleOptimTool'));
tag = 'OptimizationToolDialogRedirect';
if ~isempty(findall(0, 'Type', 'Figure', 'Name', name, 'Tag', tag))
    return
end

% uifigure
f = uifigure('Visible', false);
f.Name = name;
f.Position = [100, 100, 695, 190];
f.Tag = tag;
f.WindowStyle = 'modal';

% grid
g = uigridlayout(f);
g.RowHeight = {'fit', 'fit'};
g.ColumnWidth = {'fit'};
g.Scrollable = true;

% Message icon height/width
msgI_dim = 24;

% Message grid
msgG = uigridlayout(g);
msgG.Layout.Row = 1;
msgG.Layout.Column = 1;
msgG.RowHeight = msgI_dim;
msgG.ColumnWidth = {msgI_dim, 'fit'};
msgG.Padding = [0, 0, 0, 0];

% Message icon (error)
msgI = uiimage(msgG);
msgI.Layout.Row = 1;
msgI.Layout.Column = 1;
matlab.ui.control.internal.specifyIconID(msgI, "errorUI", msgI_dim, msgI_dim);

% Message label
msgL = uilabel(msgG);
msgL.Layout.Row = 1;
msgL.Layout.Column = 2;
msgL.Text = getString(message('optim:optimtool:DeprecationMsg','',''));
msgL.Tag = 'OptimToolDeprecationMsg';

% Select approach view
selectV = optim.internal.gui.optimize.landingpage.SelectApproachView(g);
selectV.Grid.Layout.Row = 2;

% Listen for approach selection
addlistener(selectV, 'ValueChangedEvent', @(src, event)openOptimizeTaskCallback(src, event, f));

% Center figure on the screen and make it visible
movegui(f, 'center');
f.Visible = true;
end

%--------------------------------------------------------------------------
function openOptimizeTaskCallback(~, event, f)
% Launch template Live Script

% Close uifigure
delete(f);

% Example to open depends on selection
if strcmp(event.Data, 'ProblemBased')
    exampleId = 'GetStartedWithProblemBasedOptimizeLiveEditorTaskExample';
else
    exampleId = 'GetStartedWithOptimizeLiveEditorTaskExample';
end
openExample(['optim/' exampleId]);
end
