<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>Storage</span>
    </h1>
</div>

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

            <div class="margin-top"
                data-service="storage.listBuckets"
                data-event="load,storage.createBucket,storage.updateBucket,storage.deleteBucket"
                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-buckets">

                <div data-ls-if="(!{{project-buckets.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 Buckets Found</h3>

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

                <div data-ls-if="0 != {{project-buckets.total}}">
                    <ul data-ls-loop="project-buckets.buckets" data-ls-as="bucket" data-ls-append="" class="tiles cell-3 margin-bottom-small">
                        <li class="margin-bottom">
                            <a data-ls-attrs="href=/console/storage/bucket?id={{bucket.$id}}&project={{router.params.project}}" class="box">
                                <div data-ls-bind="{{bucket.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="storage.listBuckets"
                        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-buckets"
                        data-success="state"
                        data-success-param-state-keys="search,offset">
                        <button name="offset" data-paging-back data-offset="{{router.params.offset}}" data-total="{{project-buckets.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-buckets.total|pageTotal}}"></span>

                    <form
                        data-service="storage.listBuckets"
                        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-buckets"
                        data-success="state"
                        data-success-param-state-keys="search,offset">
                        <button name="offset" data-paging-next data-offset="{{router.params.offset}}" data-total="{{project-buckets.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 Bucket">
                    <button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>

                    <h1>New Bucket</h1>

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

                        <label for="bucket-id">Bucket ID</label>
                        <input
                            type="hidden"
                            data-custom-id
                            data-id-type="auto"
                            data-validator="storage.getBucket"
                            required
                            maxlength="36"
                            pattern="^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"
                            name="bucketId" 
                            id="bucketId" />

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

                        <input type="hidden" id="bucket-permission" name="permission" required value="bucket" />
                        <input type="hidden" id="bucket-read" name="read" required data-cast-to="json" value="<?php echo htmlentities(json_encode([])); ?>" />
                        <input type="hidden" id="bucket-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>

            </li>

            <li data-state="/console/storage/usage?project={{router.params.project}}">
                <form class="pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} !== '90d'"
                    data-service="storage.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="storage.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="storage.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="storage.getUsage"
                    data-event="load"
                    data-name="usage">
                    <h3 class="margin-bottom-tiny">Objects</h3>
                    <p class="text-fade">Count of buckets, files and total storage used over time</p>
                    <div class="box">
                        <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-show-y-axis="true" data-forms-chart="Total Files=filesCount,Total Buckets=bucketsCount" data-height="140" />
                            </div>
                        </div>
                    </div>
                    <ul class="chart-notes margin-top-small margin-bottom-large">
                        <li>Total Files</li>
                        <li>Total Buckets</li>
                        <!-- <li>Total Storage <span data-ls-bind="({{usage.filesStorage|statsGetLast|statsTotal}})"></span></li> -->
                    </ul>
                    
                    <!-- CRUDS class for graph fixed colors, use color codes from Docs for CRUD operations -->
                    <h3 class="margin-bottom-tiny">Buckets</h3>
                    <p class="text-fade">Count of bucket 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 crud margin-bottom-no">
                                <input type="hidden" data-ls-bind="{{usage}}" data-forms-chart="Buckets create=bucketsCreate,Buckets read=bucketsRead,Buckets update=bucketsUpdate,Buckets delete=bucketsDelete" data-show-y-axis="true" data-colors="create,read,update,delete" data-height="140" />
                            </div>
                        </div>
                    </div>

                    <ul class="chart-notes crud margin-bottom-large">
                    <li class="green">Create</li>
                        <li class="green">Read</li>
                        <li class="green">Update</li>
                        <li class="green">Delete</li>
                    </ul>

                    <h3 class="margin-bottom-tiny">Files</h3>
                    <p class="text-fade">Count of file 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 crud margin-bottom-no">
                                <input type="hidden" data-ls-bind="{{usage}}" data-forms-chart="Files create=filesCreate,Files read=filesRead,Files update=filesUpdate,Files delete=filesDelete" data-show-y-axis="true" data-colors="create,read,update,delete" data-height="140" />
                            </div>
                        </div>
                    </div>

                    <ul class="chart-notes crud margin-bottom-large">
                    <li class="green">Create</li>
                        <li class="green">Read</li>
                        <li class="green">Update</li>
                        <li class="green">Delete</li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
</div>
