with Prompt_Pkg;
with Text_Io;
use Text_Io;

separate (Tracker)

procedure Data_Menu_Driver is
    --------------------------------------------------------------------------------
    --|
    --|  NAME:  DATA_MENU_DRIVER
    --|
    --|  OVERVIEW:
    --|    This procedure gets all the TRACKER data by controlling the printing
    --|    of the data menus, and resolving the selections to those menus.
    --|
    --|    The data menu displays different types of data.  When a data type
    --|    is chosen, an operations submenu appears, which allows the user
    --|    to manipulate the data.  Since the only operation that can be
    --|    performed on global data is modification, the user is prompted
    --|    for the new data, which is assigned directly to the global
    --|    variable rather than calling a modify procedure in global_data.
    --|
    --|  EXCEPTIONS HANDLED:
    --|    none
    --|
    --|  HISTORY:
    --|    Written by   May Lee   March 1985
    --|
    --------------------------------------------------------------------------------

    use Vt100;
    use Calendar;
    use Ss_List_Pkg;      -- to get task numbers

    Exit_Data_Menu : Boolean := False;
    Exit_Submenu : Boolean := False;

    Last : Natural;  -- used for getting an integer from a string
    Data_Menu_Selection : Integer;
    Menu_Selection : Integer;
    Found : Boolean := False;  -- parameter to find
    Ss_Name : Ss_Name_Type := (others => ' '); -- used to get task num
    Ss_Record : Subsystem_Pointer;  -- used to get task numbers

begin
    while not Exit_Data_Menu loop
        Exit_Submenu := False;
        Data_Menu_Selection := Print_Data_Menu;

        case Data_Menu_Selection is

            when 1 =>
                while not Exit_Submenu loop
                    Menu_Selection := Print_Global_Menu;

                    case Menu_Selection is
                        when 1 =>
                            Put (" The current project name is ");
                            Put (Project_Name);
                            New_Line (2);
                            Put_Line
                               (" What would you like to change the project name to? ");
                            Project_Name := Prompt_Pkg.Project_Name;
                        when 2 =>
                            Put (" The current project number is ");
                            Put (Project_Number, 3);
                            New_Line (2);
                            Put_Line
                               (" What would you like to change the project number to? ");
                            Project_Number := Prompt_Pkg.Project_Num;
                        when 3 =>
                            Put (" The current manager is ");
                            Put (Manager_Name);
                            New_Line;
                            New_Line (2);
                            Put_Line
                               (" Who would you like to be the new manager? ");
                            Manager_Name := Prompt_Pkg.Manager_Name;
                        when 4 =>
                            Put (" The current date is ");

                            if Date = Null_Date then
                                Put ("a null date ");
                            else
                                Put (Date.Month, 2);
                                Put ('/');
                                Put (Date.Day, 2);
                                Put ('/');
                                Put (Date.Year, 4);
                            end if;

                            New_Line (2);
                            Put_Line
                               (" What would you like to change the date to? ");

                            loop
                                Date := Prompt_Pkg.Date;
                                exit when Date /= Null_Date;
                                Put_Line
                                   (" The date of this run cannot be a null date.");
                                Put_Line (" Try Again!");
                            end loop;
                        when 5 =>
                            Exit_Submenu := True;
                        when others =>
                            New_Line;
                            Put_Line
                               ("Please enter a number between 1 and 5. ");
                            delay 1.0;
                    end case;
                end loop;

            when 2 =>
                while not Exit_Submenu loop
                    Menu_Selection := Print_Operation_Menu;

                    case Menu_Selection is
                        when 1 =>
                            Activity_Pkg.Ac_Add;
                        when 2 =>
                            Activity_Pkg.Ac_Delete;
                        when 3 =>
                            Activity_Pkg.Ac_Modify;
                        when 4 =>
                            Clear_Screen;
                            Prompt_Pkg.Display_Activity_Data;
                            New_Line (2);
                            Put_Line (" Press <cr> to continue");
                            Skip_Line;
                            New_Line;
                        when 5 =>
                            Exit_Submenu := True;
                        when others =>
                            New_Line;
                            Put_Line
                               ("Please enter a number between 1 and 5. ");
                            delay 1.0;
                    end case;
                end loop;

            when 3 =>
                while not Exit_Submenu loop
                    Menu_Selection := Print_Operation_Menu;

                    case Menu_Selection is
                        when 1 =>
                            Personnel_Pkg.Pr_Add;
                        when 2 =>
                            Personnel_Pkg.Pr_Delete;
                        when 3 =>
                            Personnel_Pkg.Pr_Modify;
                        when 4 =>
                            Clear_Screen;
                            Prompt_Pkg.Display_Personnel_Data;
                            New_Line (2);
                            Put_Line (" Press <cr> to continue");
                            Skip_Line;
                            New_Line;
                        when 5 =>
                            Exit_Submenu := True;
                        when others =>
                            New_Line;
                            Put_Line
                               ("Please enter a number between 1 and 5. ");
                            delay 1.0;
                    end case;
                end loop;

            when 4 =>
                while not Exit_Submenu loop
                    Menu_Selection := Print_Operation_Menu;

                    case Menu_Selection is
                        when 1 =>
                            Milestone_Pkg.Ms_Add;
                        when 2 =>
                            Milestone_Pkg.Ms_Delete;
                        when 3 =>
                            Milestone_Pkg.Ms_Modify;
                        when 4 =>
                            Clear_Screen;
                            Prompt_Pkg.Display_Milestone_Data;
                            New_Line (2);
                            Put_Line (" Press <cr> to continue");
                            Skip_Line;
                            New_Line;
                        when 5 =>
                            Exit_Submenu := True;
                        when others =>
                            New_Line;
                            Put_Line
                               ("Please enter a number between 1 and 5. ");
                            delay 1.0;
                    end case;
                end loop;

            when 5 =>
                while not Exit_Submenu loop
                    Menu_Selection := Print_Operation_Menu;

                    case Menu_Selection is
                        when 1 =>
                            Subsystem_Pkg.Ss_Add;
                        when 2 =>
                            Subsystem_Pkg.Ss_Delete;
                        when 3 =>
                            Subsystem_Pkg.Ss_Modify;
                        when 4 =>
                            Clear_Screen;
                            Prompt_Pkg.Display_Subsystem_Data;
                            New_Line (2);
                            Put_Line (" Press <cr> to continue");
                            Skip_Line;
                            New_Line;
                        when 5 =>
                            Exit_Submenu := True;
                        when others =>
                            New_Line;
                            Put_Line
                               ("Please enter a number between 1 and 5. ");
                            delay 1.0;
                    end case;
                end loop;

            when 6 =>
                while not Exit_Submenu loop
                    Menu_Selection := Print_El_Operation_Menu;

                    case Menu_Selection is
                        when 1 =>
                            Element_Pkg.El_Add;
                        when 2 =>
                            Element_Pkg.El_Delete;
                        when 3 =>
                            Element_Pkg.El_Modify;
                        when 4 =>
                            Clear_Screen;
                            Prompt_Pkg.Display_Element_Data;
                            New_Line (2);
                            Put_Line (" Press <cr> to continue");
                            Skip_Line;
                            New_Line;
                        when 5 =>
                            Element_Pkg.Update_Current;
                        when 6 =>
                            Element_Pkg.Update_Pct_Done;
                        when 7 =>
                            Exit_Submenu := True;
                        when others =>
                            New_Line;
                            Put_Line
                               ("Please enter a number between 1 and 7. ");
                            delay 1.0;
                    end case;
                end loop;

            when 7 =>
                Vt100.Clear_Screen;
                Exit_Data_Menu := True; --exit to report menu

            when others =>
                New_Line;
                Put_Line ("Please enter a number between 1 and 7. ");
                delay 1.0;
        end case;

    end loop;

end Data_Menu_Driver;