func Pages.EditUserList(tytd, ctx)
{
    tytd.Mutex.Lock();
    const db = tytd.OpenDB();
    const users = Sqlite.Exec(db,"SELECT * FROM users;");
    Sqlite.Close(db);
    tytd.Mutex.Unlock();
    const myuser = tytd.WhoAmI(ctx);
    const html = <null>
        <fieldset>
            <legend>Find by username</legend>
        <form method="GET" hx-get="./edituser" action="./edituser" hx-target="body" hx-push-url="true">
            <div class="field label border">
                <input type="text" name="user">
                <label>Username</label>
            </div>
            <button>Edit User</button>
        </form>
        </fieldset>
        
        <fieldset>
            <legend>Users</legend>
        <ul class="list border">
            <if(TypeIsList(users))>
                <true>
                    <each(var item : users)>
                        <if(item.username != myuser.username)>
                            <true>
                                <li>
                                    <a hx-get={$"./edituser?user={Net.Http.UrlEncode(item.username)}"} href={$"./edituser?user={Net.Http.UrlEncode(item.username)}"} hx-target="body" hx-push-url="true">{item.username}</a>
                                </li>
                            </true>
                        </if>
                    </each>
                </true>
            </if>
        </ul>
        </fieldset>
    </null>;

    return Components.Shell("Edit users",html, 3);
}

func Pages.EditUser(user)
{
    user.flags = ParseLong(user.flags);
    const html = <if(TypeIsDictionary(user))>
        <true>
            <h1>User: {user.username}</h1>

            <form hx-post={$"./edituser?user={Net.Http.UrlEncode(user.username)}"} hx-target="body" hx-push-url="true">
                <div class="field middle-align">
                        <nav>
                            <div class="max">
                                <h6>Is Admin</h6>
                                <div>Is an administrator (will enable all toggles)</div>
                            </div>
                            <label class="switch">
                                <if(user.flags & UserFlags.AdminFlag)>
                                    <true>
                                        <input type="checkbox" name="isAdmin" checked>
                                    </true>
                                    <false>

                                        <input type="checkbox" name="isAdmin">
                                    </false>
                                </if>
                                <span></span>
                            </label>
                        </nav>
                    </div>
                    <div class="field middle-align">
                        <nav>
                            <div class="max">
                                <h6>Plugins</h6>
                                <div>Can use plugins</div>
                            </div>
                            <label class="switch">

                                <if(user.flags & UserFlags.PluginFlag)>
                                    <true>
                                        <input type="checkbox" name="canUsePlugins" checked>
                                    </true>
                                    <false>

                                        <input type="checkbox" name="canUsePlugins">
                                    </false>
                                </if>
                                <span></span>
                            </label>
                        </nav>
                    </div>
                    <div class="field middle-align">
                        <nav>
                            <div class="max">
                                <h6>Manage plugins</h6>
                                <div>Can manage plugins (will also enable Plugins)</div>
                            </div>
                            <label class="switch">
                                 <if(user.flags & UserFlags.ManagePluginFlag)>
                                    <true>
                                        <input type="checkbox" name="canManagePlugins" checked>
                                    </true>
                                    <false>

                                        <input type="checkbox" name="canManagePlugins">
                                    </false>
                                </if>
                                <span></span>
                            </label>
                        </nav>
                    </div>
                    <div class="field middle-align">
                        <nav>
                            <div class="max">
                                <h6>Database Download</h6>
                                <div>Can download database</div>
                            </div>
                            <label class="switch">
                                <if(user.flags & UserFlags.DatabaseFlag)>
                                    <true>
                                        <input type="checkbox" name="canDownloadDB" checked>
                                    </true>
                                    <false>

                                        <input type="checkbox" name="canDownloadDB">
                                    </false>
                                </if>
                                <span></span>
                            </label>
                        </nav>
                    </div>
                    
                <button><i>save</i> Save</button>
                <button class="error-container" hx-delete={$"./edituser?user={Net.Http.UrlEncode(user.username)}"} hx-confirm="Are you sure?"><i>delete_forever</i> Delete</button>
            </form>
        </true>
        <false>
            You can{"'"}t edit yourself
        </false>
    </if>;


    return Components.Shell("Edit user",html, 3);
}