SELECT
    'dynamic' AS component,
    sqlpage.read_file_as_text('../shared/shell.json') AS properties;

-- ╭─────────────────────────────────────────────────────────╮
-- │                          Form                           │
-- ╰─────────────────────────────────────────────────────────╯
SELECT
    'form' AS component,
    'create.sql' AS "action",
    'Save' AS validate,
    'Logic Group' AS title;

SELECT
    'source_id' AS name,
    'Source' AS label,
    'select' AS TYPE,
    TRUE AS required,
    TRUE AS searchable,
    'Select...' AS empty_option,
    (
        SELECT
            jsonb_agg(jsonb_build_object('label', name, 'value', id))
        FROM
            public.sources
    ) AS options;

SELECT
    'name' AS name,
    'Name' AS label,
    8 AS width,
    TRUE AS required;

SELECT
    'uid' AS name,
    'Identifier' AS label,
    4 AS width,
    8 AS maxlength,
    1 AS minlength,
    TRUE AS required;

SELECT
    'uri' AS name,
    'URI' AS label;

-- ╭─────────────────────────────────────────────────────────╮
-- │                       Table list                        │
-- ╰─────────────────────────────────────────────────────────╯
SELECT
    'table' AS component,
    'source' AS markdown,
    TRUE AS sort,
    TRUE AS search;

SELECT
    lg.id,
    lg.uid,
    format('[%s](/sources/%s)', src.name, src.id) AS Source,
    lg.name,
    lg.uri
FROM
    public.logic_groups AS lg
    INNER JOIN public.sources AS src ON lg.source_id = src.id;
