SELECT 'dynamic' AS component, sqlpage.run_sql('shell.sql') AS properties;


--Insert new application or update existing one
INSERT INTO application (name)
SELECT :Name
WHERE :Name IS NOT NULL AND $edit IS NULL;

UPDATE application SET name = :Name WHERE id = $edit and :Name IS NOT NULL;

--Delete an application
DELETE FROM application WHERE id = $delete

SELECT 'table' AS component, 
        'id'                AS ID_Number,
        'Applications'      AS title,
        'Edit_Action'       AS markdown,
        'Remove_Action'     AS markdown,  
        TRUE                AS sort, 
        TRUE                AS search;

SELECT  id                                                  AS ID_Number,
        name                                                AS title,  
        '[Edit](applications.sql?edit=' || id || ')'        AS Edit_Action,
        '[🗑️](applications.sql?delete=' || id || ')'    AS Remove_Action
FROM application;

-- Add "Add New" button to set the $add parameter
SELECT 'button' as component, 'center' as justify;
SELECT '?add=1' as link, 'Add New' as title;  -- Dynamic link for add new

-- Display a form for adding or editing an application
SELECT 'form' AS component, 'multipart/form-data' AS enctype, 'Add an application' AS title;
SELECT  (SELECT name FROM application WHERE id = $edit) AS value, 'Name' AS name; 
