classdef CPFCCubed < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                    matlab.ui.Figure
        CheckForSBDsButton          matlab.ui.control.Button
        TabGroup                    matlab.ui.container.TabGroup
        OverviewTab                 matlab.ui.container.Tab
        SetupTab                    matlab.ui.container.Tab
        SetSBDFolderButton          matlab.ui.control.Button
        SBDFolderTextAreaLabel      matlab.ui.control.Label
        SBDFolderTextArea           matlab.ui.control.TextArea
        MissionStartDateDatePickerLabel  matlab.ui.control.Label
        MissionStartDateDatePicker  matlab.ui.control.DatePicker
        ExitButton                  matlab.ui.control.Button
    end

    properties (Access = public)
        defaultSBDFolder = '\\atlas.shore.mbari.org\projectlibrary\CPF\Operations' % Description
    end

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            app.TabGroup.SelectedTab = app.SetupTab;
            app.MissionStartDateDatePicker.Value = datetime("now", "Format", "yyyyMMMdd HH:mm");
        end

        % Button pushed function: SetSBDFolderButton
        function SetSBDFolderButtonPushed(app, event)
            folderPath = uigetdir(app.defaultSBDFolder);
            app.SBDFolderTextArea.Value = folderPath;
        end

        % Button pushed function: ExitButton
        function ExitButtonPushed(app, event)
            app.delete
        end

        % Button pushed function: CheckForSBDsButton
        function CheckForSBDsButtonPushed(app, event)
            outlook = actxserver('Outlook.Application');
            mapi=outlook.GetNamespace('mapi');
            INBOX=mapi.GetDefaultFolder(6);
        end

        % Value changed function: MissionStartDateDatePicker
        function MissionStartDateDatePickerValueChanged(app, event)
            value = app.MissionStartDateDatePicker.Value;

        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 640 480];
            app.UIFigure.Name = 'MATLAB App';

            % Create CheckForSBDsButton
            app.CheckForSBDsButton = uibutton(app.UIFigure, 'push');
            app.CheckForSBDsButton.ButtonPushedFcn = createCallbackFcn(app, @CheckForSBDsButtonPushed, true);
            app.CheckForSBDsButton.Position = [34 31 108 29];
            app.CheckForSBDsButton.Text = 'Check For SBDs';

            % Create TabGroup
            app.TabGroup = uitabgroup(app.UIFigure);
            app.TabGroup.Position = [34 81 536 323];

            % Create OverviewTab
            app.OverviewTab = uitab(app.TabGroup);
            app.OverviewTab.Title = 'Overview';

            % Create SetupTab
            app.SetupTab = uitab(app.TabGroup);
            app.SetupTab.Title = 'Setup';

            % Create SetSBDFolderButton
            app.SetSBDFolderButton = uibutton(app.SetupTab, 'push');
            app.SetSBDFolderButton.ButtonPushedFcn = createCallbackFcn(app, @SetSBDFolderButtonPushed, true);
            app.SetSBDFolderButton.Position = [5 221 120 33];
            app.SetSBDFolderButton.Text = 'Set SBD Folder';

            % Create SBDFolderTextAreaLabel
            app.SBDFolderTextAreaLabel = uilabel(app.SetupTab);
            app.SBDFolderTextAreaLabel.HorizontalAlignment = 'right';
            app.SBDFolderTextAreaLabel.Position = [57 253 68 22];
            app.SBDFolderTextAreaLabel.Text = 'SBD Folder';

            % Create SBDFolderTextArea
            app.SBDFolderTextArea = uitextarea(app.SetupTab);
            app.SBDFolderTextArea.Position = [140 221 339 56];

            % Create MissionStartDateDatePickerLabel
            app.MissionStartDateDatePickerLabel = uilabel(app.SetupTab);
            app.MissionStartDateDatePickerLabel.HorizontalAlignment = 'right';
            app.MissionStartDateDatePickerLabel.Position = [5 164 104 22];
            app.MissionStartDateDatePickerLabel.Text = 'Mission Start Date';

            % Create MissionStartDateDatePicker
            app.MissionStartDateDatePicker = uidatepicker(app.SetupTab);
            app.MissionStartDateDatePicker.DisplayFormat = 'uuuuMMMdd';
            app.MissionStartDateDatePicker.ValueChangedFcn = createCallbackFcn(app, @MissionStartDateDatePickerValueChanged, true);
            app.MissionStartDateDatePicker.Position = [124 153 113 33];

            % Create ExitButton
            app.ExitButton = uibutton(app.UIFigure, 'push');
            app.ExitButton.ButtonPushedFcn = createCallbackFcn(app, @ExitButtonPushed, true);
            app.ExitButton.Position = [512 31 97 29];
            app.ExitButton.Text = 'Exit';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = CPFCCubed

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end