<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 link-return-animation--start"><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/databases?project={{router.params.project}}">
            <h2>Databases</h2>

            <div class="margin-top"
                data-service="databases.list"
                data-event="load,databases.create,databases.update,databases.delete"
                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-databases">

                <div data-ls-if="(!{{project-databases.total}})" 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 Databases Found</h3>

                        <p class="margin-bottom-no">You haven't created any databases for your project yet.</p>
                    </div>
                </div>

                <div data-ls-if="0 != {{project-databases.total}}">
                    <ul data-ls-loop="project-databases.databases" data-ls-as="database" data-ls-append="" class="tiles cell-3 margin-bottom-small">
                        <li class="margin-bottom">
                            <a data-ls-attrs="href=/console/databases/database?id={{database.$id}}&project={{router.params.project}}" class="box">
                                <div data-ls-bind="{{database.name}}" class="text-one-liner margin-bottom text-bold">&nbsp;</div>

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

                <div class="pull-end text-align-center paging">
                    <form
                        data-service="databases.list"
                        data-event="submit"
                        data-param-search="{{router.params.search}}"
                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                        data-param-order-type="ASC"
                        data-scope="sdk"
                        data-name="project-databases"
                        data-success="state"
                        data-success-param-state-keys="search,offset">
                        <button name="offset" data-paging-back data-offset="{{router.params.offset}}" data-total="{{project-databases.total}}" 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-databases.total|pageTotal}}"></span>

                    <form
                        data-service="databases.list"
                        data-event="submit"
                        data-param-search="{{router.params.search}}"
                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                        data-param-order-type="ASC"
                        data-scope="sdk"
                        data-name="project-databases"
                        data-success="state"
                        data-success-param-state-keys="search,offset">
                        <button name="offset" data-paging-next data-offset="{{router.params.offset}}" data-total="{{project-databases.total}}" class="margin-start round small" aria-label="Next"><i class="icon-right-open"></i></button>
                    </form>
                </div>

                <div data-ui-modal class="modal close box sticky-footer" data-button-text="Add Database">
                    <button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>

                    <h1>New Database</h1>

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

                        <label for="database-id">Database ID</label>
                        <input
                            type="hidden"
                            data-custom-id
                            data-id-type="auto"
                            data-validator="databases.get"
                            required
                            maxlength="36"
                            pattern="^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
                            name="databaseId" />

                        <label for="database-name">Name</label>
                        <input type="text" class="full-width" id="database-name" name="name" required autocomplete="off" maxlength="128" />
                        <hr />

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

            </li><!-- TODO need to work on usage -->
            <li data-state="/console/databases/usage?project={{router.params.project}}">
                <form class="pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} !== '90d'"
                    data-service="databases.getUsage"
                    data-event="submit"
                    data-name="usage"
                    data-param-range="90d">
                    <button class="tick">90d</button>
                </form>

                <button class="tick pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} === '90d'" disabled>90d</button>

                <form class="pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} !== '30d'"
                    data-service="databases.getUsage"
                    data-event="submit"
                    data-name="usage">
                    <button class="tick">30d</button>
                </form>

                <button class="tick pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} === '30d'" disabled>30d</button>

                <form class="pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} !== '24h'"
                    data-service="databases.getUsage"
                    data-event="submit"
                    data-name="usage"
                    data-param-range="24h">
                    <button class="tick">24h</button>
                </form>

                <button class="tick pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} === '24h'" disabled>24h</button>

                <h2>Usage</h2>

                <div
                    data-service="databases.getUsage"
                    data-event="load"
                    data-name="usage">
                    <h3 class="margin-bottom-tiny">Objects</h3>
                    <p class="text-fade">Count of collections and documents over time</p>
                    <div class="box margin-bottom-small">
                        <div class="margin-start-negative-small margin-end-negative-small margin-top-negative-small margin-bottom-negative-small">
                            <div class="chart background-image-no border-no margin-bottom-no">
                                <input 
                                type="hidden" 
                                data-ls-bind="{{usage}}" 
                                data-forms-chart="Databases=databasesCount,Collections=collectionsCount,Documents=documentsCount" 
                                data-show-y-axis="true"
                                data-height="140" />
                            </div>
                        </div>
                    </div>

                    <ul class="chart-notes margin-bottom-large">
                        <li>Total Databases <span data-ls-bind="({{usage.databasesCount|statsGetLast|statsTotal}})"></span></li>
                        <li>Total Collections <span data-ls-bind="({{usage.collectionsCount|statsGetLast|statsTotal}})"></span></li>
                        <li>Total Documents <span data-ls-bind="({{usage.documentsCount|statsGetLast|statsTotal}})"></span></li>
                    </ul>

                    <h3 class="margin-bottom-tiny">Databases</h3>
                    <p class="text-fade">Count of databases create, read, update and delete operations over time</p>
                    <div class="box margin-bottom-small">
                        <div class="margin-start-negative-small margin-end-negative-small margin-top-negative-small margin-bottom-negative-small">
                            <div class="chart background-image-no border-no margin-bottom-no">
                                <input 
                                    type="hidden"
                                    data-ls-bind="{{usage}}"
                                    data-forms-chart="Created=databasesCreate,Read=databasesRead,Updated=databasesUpdate,Deleted=databasesDelete"
                                    data-show-y-axis="true"
                                    data-colors="create,read,update,delete"
                                    data-height="140" />
                            </div>
                        </div>
                    </div>

                    <ul class="chart-notes margin-bottom-large crud">
                        <li>Created</li>
                        <li>Read</li>
                        <li>Updated</li>
                        <li>Deleted</li>
                    </ul>

                    <h3 class="margin-bottom-tiny">Collections</h3>
                    <p class="text-fade">Count of collections create, read, update and delete operations over time</p>
                    <div class="box margin-bottom-small">
                        <div class="margin-start-negative-small margin-end-negative-small margin-top-negative-small margin-bottom-negative-small">
                            <div class="chart background-image-no border-no margin-bottom-no">
                                <input 
                                    type="hidden"
                                    data-ls-bind="{{usage}}"
                                    data-forms-chart="Created=collectionsCreate,Read=collectionsRead,Updated=collectionsUpdate,Deleted=collectionsDelete"
                                    data-show-y-axis="true"
                                    data-colors="create,read,update,delete"
                                    data-height="140" />
                            </div>
                        </div>
                    </div>

                    <ul class="chart-notes margin-bottom-large crud">
                        <li>Created</li>
                        <li>Read</li>
                        <li>Updated</li>
                        <li>Deleted</li>
                    </ul>

                    <h3 class="margin-bottom-tiny">Documents</h3>
                    <p class="text-fade">Count of documents create, read, update and delete operations over time</p>
                    <div class="box margin-bottom-small">
                        <div class="margin-start-negative-small margin-end-negative-small margin-top-negative-small margin-bottom-negative-small">
                            <div class="chart background-image-no border-no margin-bottom-no">
                                <input
                                    type="hidden"
                                    data-ls-bind="{{usage}}"
                                    data-forms-chart="Created=documentsCreate,Read=documentsRead,Updated=documentsUpdate,Deleted=documentsDelete"
                                    data-show-y-axis="true"
                                    data-colors="create,read,update,delete"
                                    data-height="140" />
                            </div>
                        </div>
                    </div>

                    <ul class="chart-notes margin-bottom-large crud">
                        <li>Created</li>
                        <li>Read</li>
                        <li>Updated</li>
                        <li>Deleted</li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
</div>
