<div class="cover">
    <h1 class="zone xxl margin-bottom-large margin-top">
        Database
    </h1>
</div>

<div data-ui-modal class="box modal close" data-open-event="create-collection" data-button-alias="create-collection">
    <button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>

    <h1>Create Collection</h1>

    <p>Currently this feature is only available using the Appwrite API. To learn more about how to use it, visit our <a href="" data-ls-attrs="href={{env.HOME}}/docs/database" target="_blank">documentation</a>.</p>
</div>

<div data-ui-modal class="box modal close" data-open-event="create-document" data-button-alias="create-documnet">
    <button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>

    <h1>Create Document</h1>

    <p>Currently this feature is only available using the Appwrite API. To learn more about how to use it, visit our <a href="" data-ls-attrs="href={{env.HOME}}/docs/database" target="_blank">documentation</a>.</p>
</div>

<div class="zone xxl">
    <ul class="phases clear" data-ui-phases data-selected="{{router.params.tab}}">
        <li data-state="/console/users?project={{router.params.project}}">
        
            <h2 style="display: none;">Explore</h2>

            <div class="box dashboard database margin-bottom-xl">
                <div class="row responsive">
                    <div class="col span-3">
                        <h3>
                            <b data-ls-if="({{project-collections.sum}})" data-ls-bind="Collections ({{project-collections.sum|localeString}})"></b>
                        </h3>

                        <form class="search"
                            data-service="database.listCollections"
                            data-event="submit"
                            data-param-search="{{router.params.search}}"
                            data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                            data-param-offset=""
                            data-param-order-type="DESC"
                            data-scope="sdk"
                            data-name="project-collections"
                            data-success="state"
                            data-success-param-state-keys="search,offset">
                            <input name="search" id="searchCollection" type="search" autocomplete="off" placeholder="Search" class="margin-bottom-no" data-ls-bind="{{router.params.search}}">
                        </form>
                        
                        <hr />
                        
                        <button data-ls-ui-trigger="create-collection" class="button link"><i class="icon-plus"></i> Add collection</button>

                        <div class="wrapper"
                            data-service="database.listCollections"
                            data-event="load,collection-create,collection-update,collection-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="DESC"
                            data-scope="sdk"
                            data-name="project-collections">

                            <div data-ls-if="0 == {{project-collections.sum}}" class="empty">
                                <h4>No Collections Found</h4>
                            </div>

                            <div data-ls-if="0 != {{project-collections.sum}}">
                                <ul data-ls-loop="project-collections.collections" data-ls-as="collection" class="items">
                                    <li data-ls-attrs="class={{collection.$uid|selectedCollection}},data-uid={{router.params.collectionId}}">
                                        <form
                                            data-service="database.listDocuments"
                                            data-event="submit"
                                            data-param-search=""
                                            data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                                            data-param-offset=""
                                            data-param-order-type="DESC"
                                            data-scope="sdk"
                                            data-name="project-documents"
                                            data-success="state"
                                            data-success-param-state-keys="collectionId=collectionId,search=dsearch,offset=doffset">
                                            <input name="collectionId" data-ls-bind="{{collection.$uid}}" type="hidden" />
                                            <button><span data-ls-bind="{{collection.$uid}}"></span></button>
                                        </form>

                                        <i class="icon-right-open pull-end"></i>
                                        <span class="name text-one-liner" data-ls-bind="{{collection.name}}"></span>
                                    </li>
                                </ul>
                            </div>

                            <hr />

                            <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>
                        </div>
                    </div>
                    <div class="col span-3">
                        
                        <h3>
                            <b data-ls-if="(({{router.params.collectionId}}) && ({{project-documents.sum}} >= 0))" data-ls-bind="{{project-documents.name}} ({{project-documents.sum|localeString}})"></b>
                        </h3>

                        <div data-ls-if="({{router.params.collectionId}})" style="display: none">
                            <form class="search"
                                data-service="database.listDocuments"
                                data-event="submit"
                                data-param-collection-id="{{router.params.collectionId}}"
                                data-param-search="{{router.params.dsearch}}"
                                data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                                data-param-offset=""
                                data-param-order-type="DESC"
                                data-scope="sdk"
                                data-name="project-documents"
                                data-success="state"
                                data-success-param-state-keys="dsearch,doffset">
                                <input name="dsearch" id="searchDocuments" type="search" autocomplete="off" placeholder="Search" class="margin-bottom-no" data-ls-bind="{{router.params.dsearch}}">
                            </form>

                            <hr />

                            <button data-ls-ui-trigger="create-document" class="button link"><i class="icon-plus"></i> Add document</button>

                            <div class="wrapper"
                                data-service="database.listDocuments"
                                data-event="load,document-create,document-update,document-delete"
                                data-param-collection-id="{{router.params.collectionId}}"
                                data-param-search="{{router.params.dsearch}}"
                                data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                                data-param-offset="{{router.params.doffset}}"
                                data-param-order-type="DESC"
                                data-scope="sdk"
                                data-name="project-documents">

                                <div data-ls-if="0 == {{project-documents.sum}}" class="empty">
                                    <h4>No Documents Found</h4>
                                </div>

                                <div data-ls-if="0 != {{project-documents.sum}}">
                                    <ul data-ls-loop="project-documents.documents" data-ls-as="node" class="items">
                                        <li data-ls-attrs="class={{node.$uid|selectedDocument}},data-uid={{router.params.documentId}}">
                                            <form
                                                data-service="database.getDocument"
                                                data-event="submit"
                                                data-scope="sdk"
                                                data-name="project-document"
                                                data-success="state"
                                                data-success-param-state-keys="documentId=documentId">
                                                <input name="collectionId" data-ls-bind="{{router.params.collectionId}}" type="hidden" />
                                                <input name="documentId" data-ls-bind="{{node.$uid}}" type="hidden" />
                                                <button><span data-ls-bind="{{node.$uid}}"></span></button>
                                            </form>

                                            <i class="icon-right-open pull-end"></i>
                                            <span data-ls-bind="{{node.$uid}}"></span>
                                        </li>
                                    </ul>
                                </div>

                                <hr />

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

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

                                    <form
                                        data-service="database.listDocuments"
                                        data-event="submit"
                                        data-param-collection-id="{{router.params.collectionId}}"
                                        data-param-search="{{router.params.dsearch}}"
                                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                                        data-param-order-type="DESC"
                                        data-scope="sdk"
                                        data-name="project-documents"
                                        data-success="state"
                                        data-success-param-state-keys="search=dsearch,offset=doffset">
                                        <button name="offset" data-paging-next data-offset="{{router.params.doffset}}" data-sum="{{project-documents.sum}}" class="margin-start round small" aria-label="Next"><i class="icon-right-open"></i></button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col span-6">
                        <h3>
                            <b data-ls-if="({{project-document.$uid}})">Preview</b>
                        </h3>
                        
                        <div
                            data-service="database.getDocument"
                            data-event="load"
                            data-scope="sdk"
                            data-name="project-document"
                            data-param-collection-id="{{router.params.collectionId}}"
                            data-param-document-id="{{router.params.documentId}}"
                            data-success="state"
                            data-success-param-state-keys="documentId=documentId">
                        </div>

                        <div data-ls-if="({{project-document.$uid}})" style="display: none">
                            
                            <div class="code">
                                <input type="hidden" data-forms-code data-ls-bind="{{project-document}}" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </li>
    </ul>
</div>