function [ ] = main(pCallbacks)
%MAIN Contains the definition of main ARTOA4 gui.

global artoaGui;

%% Initialize callbacks

availableCallbacks = { ...
    'CloseRequestFcn', ...
    'WindowButtonDownFcn', ...
    'loadRfb', ...
    'loadInterim', ...
    'loadSoundsourceFile', ...
    'saveRfc', ...
    'saveInterim', ...
    'saveOptimumTables', ...
    'loadArtoaIni', ...
    'quit', ...
    'openEditTemperature', ...
    'openEditPressure', ...
    'openEditTimeOfArrival', ...
    'openEditOffsets', ...
    'openTrackParameter', ...
    'openTrackTrajectoryOutput', ...
    'switchHideDeletedDataPoints' ...
};

for i = 1:length(availableCallbacks) % check if a callback is undefined
    if ~isfield(pCallbacks, availableCallbacks{i})
        pCallbacks.(availableCallbacks{i}) = @(~, ~) false;
    end
end

%% Initialize main window

artoaGui.figures.main = figure( ...
    'Name', 'ARTOA 4', ...
    'NumberTitle', 'off', ...
    'Color', 'white', ...
    'MenuBar', 'none', ...
    'Units', 'characters', ...
    'WindowKeyPressFcn', @artoa.controller.main.shortcuts ...
);

artoaGui.figures.main.Position(3) = 70;
artoaGui.figures.main.Position(4) = 15;

set(artoaGui.figures.main, 'CloseRequestFcn', pCallbacks.CloseRequestFcn);
set(artoaGui.figures.main, 'WindowButtonDownFcn', pCallbacks.WindowButtonDownFcn);

%% Initialize file menu
artoaGui.main.menus = struct();

artoaGui.main.menus.file = uimenu(artoaGui.figures.main, 'Label', 'File');
% LOAD
loadHandle = uimenu(artoaGui.main.menus.file, 'Label', 'Load');
uimenu( ...
    loadHandle, ...
    'Label', 'ARGOS file', ...%'Callback', 'artoa.controller.loadArgos' ...
    'Enable', 'off' ...
);
uimenu( ...
    loadHandle, ...
    'Label', 'RFB file', ...
    'Callback', pCallbacks.loadRfb ...
);
uimenu( ...
    loadHandle, ...
    'Label', 'Interim file', ...
    'Callback', pCallbacks.loadInterim ...
);
uimenu( ...
    loadHandle, ...
    'Label', 'SoSo file', ...
    'Callback', pCallbacks.loadSoundsourceFile ...
);


% SAVE
artoaGui.main.menus.fileSave = uimenu( ...
    artoaGui.main.menus.file, ...
    'Label', 'Save', ...
    'Enable', 'off' ...
);

uimenu( ...
    artoaGui.main.menus.fileSave, ...
    'Label', 'RFC file', ...
    'Callback', pCallbacks.saveRfc ...
);

uimenu( ...
    artoaGui.main.menus.fileSave, ...
    'Label', 'Interim file', ...
    'Callback', pCallbacks.saveInterim ...
);

uimenu( ...
    artoaGui.main.menus.fileSave, ...
    'Label', 'Optimum tables', ...
    'Callback', pCallbacks.saveOptimumTables ...
);

artoaGui.main.menus.fileReloadArtoaIni = uimenu( ...
    artoaGui.main.menus.file, ...
    'Label', 'Reload artoa.ini', ...
    'Callback', pCallbacks.loadArtoaIni ...
);

% QUIT
artoaGui.main.menus.fileQuit = uimenu( ...
    artoaGui.main.menus.file, ...
    'Label', 'Quit', ...
    'Callback', pCallbacks.quit ...
);

%% Initialize edit menu

artoaGui.main.menus.edit = uimenu( ...
    artoaGui.figures.main, ...
    'Label', 'Edit', ...
    'Enable', 'off' ...
);

% TEMPERATURE
artoaGui.main.menus.editTemperature = uimenu( ...
    artoaGui.main.menus.edit, ...
    'Label', 'Temperature', ...
    'Callback', pCallbacks.openEditTemperature ...
);

% PRESSURE
artoaGui.main.menus.editPressure = uimenu( ...
    artoaGui.main.menus.edit, ...
    'Label', 'Pressure', ...
    'Callback', pCallbacks.openEditPressure ...
);

% TIME OF ARRIVAL
artoaGui.main.menus.editTimeOfArrival = uimenu( ...
    artoaGui.main.menus.edit, ...
    'Label', 'Time of arrival', ...
    'Callback', pCallbacks.openEditTimeOfArrival, ...
    'Separator', 'on', ...
    'Enable', 'off' ...
);

artoaGui.main.menus.editOffsetDetails = uimenu( ...
    artoaGui.main.menus.edit, ...
    'Label', 'Offset details', ...
    'Callback', pCallbacks.openEditOffsets, ...
    'Separator', 'on' ...
);

%% Initialize track menu

artoaGui.main.menus.track = uimenu( ...
    artoaGui.figures.main, ...
    'Label', 'Track', ...
    'Enable', 'off' ...
);

% TRACK PARAMETER
artoaGui.main.menus.trackParameter = uimenu( ...
    artoaGui.main.menus.track, ...
    'Label', 'Track Parameter', ...
    'Callback', pCallbacks.openTrackParameter ...
);

% TRAJECTORY OUTPUT
artoaGui.main.menus.trajectoryOutput = uimenu( ...
    artoaGui.main.menus.track, ...
    'Label', 'Trajectory output', ...
    'Callback', pCallbacks.openTrackTrajectoryOutput ...
);


%% Initialize view menu

artoaGui.main.menus.view = uimenu( ...
    artoaGui.figures.main, ...
    'Label', 'View', ...
    'Enable', 'on' ...
);

artoaGui.main.menus.viewHideDeletedDataPoints = uimenu( ...
    artoaGui.main.menus.view, ...
    'Label', 'Hide deleted data points', ...
    'Callback', pCallbacks.switchHideDeletedDataPoints ...
);

%% Initialize shortcut hints

shortcutHints = { ...
    't', 'Open Edit temperature window';
    'p', 'Open Edit pressure window';
    'e', 'Open Edit time of arrival window';
    'f', 'Open Edit offsets window';
    'i', 'Open track parameter window';
    'o', 'Open trajectory output window';
};

artoaGui.main.shortcutHints = uitable();
artoaGui.main.shortcutHints.Data = shortcutHints;
artoaGui.main.shortcutHints.Enable = 'off';
artoaGui.main.shortcutHints.ColumnName = {'Key', 'Action'};
artoaGui.main.shortcutHints.ColumnWidth = {50, 340};
artoaGui.main.shortcutHints.RowName = '';
artoaGui.main.shortcutHints.Units = 'normalized';
artoaGui.main.shortcutHints.Position = [.05 .125 .9 .8];



%% Version info

gitInfo = getGitInfo();

artoaGui.main.textVersionInfo = uicontrol( ...
    'Parent', artoaGui.figures.main, ...
    'String', artoa.controller.main.getVersionString(), ...
    'Style', 'text', ...
    'FontSize', 10, ...
    'Units', 'normalized', ...
    'Background', [1 1 1], ...
    'Position', [.7 .02 .25 .08] ...
);


end

