<div class="cover">
    <h1 class="zone xl margin-bottom-large">
        <a data-ls-attrs="href=/console/home?project={{router.params.project}}" class="back text-size-small"><i class="icon-left-open"></i> Home</a>
        <br />

        <span>Database</span>
    </h1>
</div>

<div class="zone xl">
    <ul class="phases clear" data-ui-phases data-selected="{{router.params.tab}}">
        <li data-state="/console/database?project={{router.params.project}}">
            <h2>Collections</h2>

            <div data-ui-modal class="box modal close" data-button-text="" data-button-class="fly round" data-button-icon="icon-plus">
                <button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>

                <h1>New Collection</h1>

                <form
                    data-analytics-event="submit"
                    data-analytics-category="console"
                    data-analytics-label="Create Database Collection"
                    data-service="database.createCollection"
                    data-event="submit"
                    data-scope="sdk"
                    data-success="alert,reset,redirect,trigger"
                    data-success-param-alert-text="Collection created successfully"
                    data-success-param-redirect-url="/console/database/collection/settings?id={{serviceData.$id}}&project={{router.params.project}}"
                    data-success-param-trigger-events="database.createCollection"
                    data-failure="alert"
                    data-failure-param-alert-text="Failed to create collection"
                    data-failure-param-alert-classname="error">

                    <label for="user-name">Name</label>
                    <input type="text" class="full-width" id="collection-name" name="name" required autocomplete="off" />

                    <input type="hidden" id="collection-read" name="read" required data-cast-to="json" value="<?php echo htmlentities(json_encode([])); ?>" />
                    <input type="hidden" id="collection-write" name="write" required data-cast-to="json" value="<?php echo htmlentities(json_encode([])); ?>" />

                    <hr />

                    <button type="submit">Create</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
                </form>
            </div>

            <div class="margin-top"
                data-service="database.listCollections"
                data-event="load,database.createCollection,database.updateCollection,database.deleteCollection"
                data-param-search="{{router.params.search}}"
                data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                data-param-offset="{{router.params.offset}}"
                data-param-order-type="ASC"
                data-scope="sdk"
                data-name="project-collections">

                <div data-ls-if="(!{{project-collections.sum}})" class="box dashboard margin-bottom">
                    <div class="margin-bottom-small margin-top-small margin-end margin-start">
                        <h3 class="margin-bottom-small text-bold">No Collections Found</h3>

                        <p class="margin-bottom-no">You haven't created any collections for your project yet.</p>
                    </div>
                </div>
                
                <div data-ls-if="0 != {{project-collections.sum}}">
                    <ul data-ls-loop="project-collections.collections" data-ls-as="collection" data-ls-append="" class="tiles cell-3 margin-bottom-small" style="visibility: hidden">
                        <li class="margin-bottom">
                            <a data-ls-attrs="href=/console/database/collection?id={{collection.$id}}&project={{router.params.project}}" class="box">
                                <div data-ls-bind="{{collection.name}}" class="text-one-liner margin-bottom text-bold">&nbsp;</div>

                                <i class="icon-right-open"></i>
                            </a>
                        </li>
                    </ul>
                </div>

                <div class="clear text-align-center paging">
                    <form
                        data-service="database.listCollections"
                        data-event="submit"
                        data-param-search="{{router.params.search}}"
                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                        data-param-order-type="DESC"
                        data-scope="sdk"
                        data-name="project-collections"
                        data-success="state"
                        data-success-param-state-keys="search,offset">
                        <button name="offset" data-paging-back data-offset="{{router.params.offset}}" data-sum="{{project-collections.sum}}" class="margin-end round small" aria-label="Back"><i class="icon-left-open"></i></button>
                    </form>

                    <span data-ls-bind="{{router.params.offset|pageCurrent}} / {{project-collections.sum|pageTotal}}"></span>

                    <form
                        data-service="database.listCollections"
                        data-event="submit"
                        data-param-search="{{router.params.search}}"
                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                        data-param-order-type="DESC"
                        data-scope="sdk"
                        data-name="project-collections"
                        data-success="state"
                        data-success-param-state-keys="search,offset">
                        <button name="offset" data-paging-next data-offset="{{router.params.offset}}" data-sum="{{project-collections.sum}}" class="margin-start round small" aria-label="Next"><i class="icon-right-open"></i></button>
                    </form>
                </div>
            </li>
            <!-- <li data-state="/console/database/usage?project={{router.params.project}}">
                <h2>Usage</h2>
            </li> -->
        </ul>
    </div>
</div>