<div class="cover">
    <h1 class="zone xl margin-bottom-large">
        <a data-ls-attrs="href=/console" class="back text-size-small link-return-animation--start"><i class="icon-left-open"></i> Home</a>
        <br />

        <span>Your Account</span>
    </h1>
</div>

<div class="zone xl">
    <ul class="phases clear" data-ui-phases data-selected="{{router.params.tab}}">
        <li data-state="/console/account">
            <h2 class="margin-bottom">Overview</h2>
            
            <div
                data-service="account.get"
                data-scope="console"
                data-name="account"
                data-event="load"
                data-failure="trigger"
                data-failure-param-trigger-events="account.deleteSession">

                <div class="row responsive force-reverse">
                    <div class="col span-3 text-align-center margin-bottom">
                        <img src="" data-ls-attrs="src={{account|avatar}}" data-size="200" height="150" alt="User Avatar" class="avatar huge huge margin-bottom-small" />
                    </div>

                    <div class="col span-9">
                        <div class="box margin-bottom-xl">
                            <div>
                                <form name="account.update"
                                    data-analytics
                                    data-analytics-activity
                                    data-analytics-event="submit"
                                    data-analytics-category="console"
                                    data-analytics-label="Update Account Name"
                                    data-service="account.updateName"
                                    data-scope="console"
                                    data-event="submit"
                                    data-success="trigger,alert"
                                    data-success-param-alert-text="Your name was updated successfully"
                                    data-success-param-trigger-events="account.update"
                                    data-failure="alert"
                                    data-failure-param-alert-text="Failed to update your name"
                                    data-failure-param-alert-classname="error">

                                    <label for="name">Name</label>

                                    <div class="row responsive">
                                        <div class="col span-8 margin-bottom-small">
                                            <input name="name" id="name" type="text" autocomplete="off" data-ls-bind="{{account.name}}" required class="margin-bottom-no" maxlength="128">
                                        </div>
                                        <div class="col span-4">
                                            <button type="submit" class="fill margin-bottom-no">Update Name</button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <hr />

                            <form name="update-email"
                                data-analytics
                                data-analytics-activity
                                data-analytics-event="submit"
                                data-analytics-category="console"
                                data-analytics-label="Update Account Email"
                                data-service="account.updateEmail"
                                data-scope="console"
                                data-event="submit"
                                data-success="trigger,alert"
                                data-success-param-alert-text="Email address updated successfully"
                                data-success-param-trigger-events="account-update,modal-close" 
                                data-failure="alert"
                                data-failure-param-alert-text="Failed updating email address"
                                data-failure-param-alert-classname="error">

                                <label>Email</label>
                                <div class="row responsive">
                                    <div class="col span-8 margin-bottom-small">
                                        <input name="email" type="email" class="margin-bottom-no" autocomplete="off" placeholder="me@example.com" data-ls-bind="{{account.email}}" required>
                                    </div>
                                    <div class="col span-4">
                                        <div data-ui-modal class="modal box close width-small height-small" data-button-text="Update Email" data-button-class="fill">
                                            <h3>Confirm Password</h3>
                                            
                                            <hr />

                                            <label>Password</label>
                                            <input name="password" type="password" class="full-width" autocomplete="off" placeholder="" required>
                                            
                                            <hr />

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

                            <hr />

                            <div data-ui-modal class="modal box close width-small" data-button-text="Update Password" data-button-class="">
                                <h1>Update Password</h1>

                                <form name="update-password"
                                    data-analytics
                                    data-analytics-activity
                                    data-analytics-event="submit"
                                    data-analytics-category="console"
                                    data-analytics-label="Update Account Password"
                                    data-service="account.updatePassword"
                                    data-scope="console"
                                    data-event="submit"
                                    data-success="trigger,alert,reset"
                                    data-success-param-trigger-events="account-update"
                                    data-success-param-alert-text="Password updated successfully"
                                    data-failure="alert"
                                    data-failure-param-alert-text="Failed updating password"
                                    data-failure-param-alert-classname="error">

                                    <label>Current Password</label>
                                    <input name="oldPassword" type="password" class="full-width" autocomplete="off" placeholder="" required>

                                    <label>New Password</label>
                                    <input name="password" type="password" class="full-width" autocomplete="off" placeholder="" required data-forms-password-meter>

                                    <hr />

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

                            <hr />

                            <form class="margin-top"
                                data-analytics
                                data-analytics-activity
                                data-analytics-event="submit"
                                data-analytics-category="console"
                                data-analytics-label="Delete Account Current Session"
                                data-service="account.deleteSession"
                                data-scope="console"
                                data-event="submit"
                                data-success="trigger"
                                data-success-param-trigger-events="account.deleteSession"
                                data-failure="alert"
                                data-failure-param-alert-text="Logout failed"
                                data-failure-param-alert-classname="error">

                                <input type="hidden" name="sessionId" value="current">

                                <button class="fill danger icon fill"><i class="icon-login"></i> Logout</button>
                            </form>
                        </div>

                    </div>
                </div>

                <div class="row responsive">
                    <div class="col span-9">

                        <h3 class="text-danger">Danger Zone</h3>

                        <div class="box danger">
                            <p>This is the area where you can delete your account.</p>

                            <p>By deleting your account you will lose access to any of your teams and shared data.</p>

                            <p>PLEASE NOTE: Account deletion is irreversible.</p>

                            <form class="inline"
                                data-analytics
                                data-analytics-activity
                                data-analytics-event="submit"
                                data-analytics-category="console"
                                data-analytics-label="Delete Account"
                                data-service="account.delete"
                                data-scope="console"
                                data-event="submit"
                                data-confirm="Are you sure you want to delete your account?"
                                data-success="trigger"
                                data-success-param-trigger-events="account.delete"
                                data-failure="alert"
                                data-failure-param-alert-text="Account deactivation failed"
                                data-failure-param-alert-classname="error">
                                <button class="danger reverse">Delete Account</button>
                            </form>
                        </div>
                    </div>
                    <div class="col span-3"></div>
                </div>
            </div>
        </li>
        <li data-state="/console/account/sessions">
            <h2>Sessions</h2>

            <div class="box margin-bottom"
                data-service="account.getSessions"
                data-scope="console"
                data-name="sessions"
                data-event="load,account.deleteRemoteSession">

                <ul data-ls-loop="sessions.sessions" data-ls-as="session" class="list">
                    <li class="clear">
                        <span data-ls-if="true != {{session.current}}">
                            <!-- From remote session (-logout event) -->
                            <form class="pull-end"
                                data-analytics
                                data-analytics-activity
                                data-analytics-event="submit"
                                data-analytics-category="console"
                                data-analytics-label="Delete Account Session"
                                data-service="account.deleteSession"
                                data-scope="console"
                                data-event="submit"
                                data-loading="Loading..."
                                data-success="trigger"
                                data-success-param-trigger-events="account.deleteRemoteSession"
                                data-failure="alert"
                                data-failure-param-alert-text="Logout from Session Failed"
                                data-failure-param-alert-classname="error">

                                <input type="hidden" name="sessionId" data-ls-bind="{{session.$id}}">
                                <button class="danger">Logout</button>
                            </form>
                        </span>

                        <span data-ls-if="true == {{session.current}}">
                            <!-- From current session (+logout event) -->
                            <form class="pull-end"
                                data-analytics
                                data-analytics-activity
                                data-analytics-event="submit"
                                data-analytics-category="console"
                                data-analytics-label="Delete Account Current Session"
                                data-service="account.deleteSession"
                                data-scope="console"
                                data-event="submit"
                                data-loading="Loading..."
                                data-success="trigger,redirect"
                                data-success-param-trigger-events="account.deleteSession"
                                data-success-param-redirect-url="/"
                                data-failure="alert"
                                data-failure-param-alert-text="Logout from Session Failed"
                                data-failure-param-alert-classname="error">
                                <input type="hidden" name="sessionId" data-ls-bind="{{session.$id}}">
                                <button class="danger">Logout</button>
                            </form>
                        </span>

                        <div class="pull-start margin-end avatar-container">
                            <img onerror="this.onerror=null;this.className='avatar hide'" data-ls-attrs="src={{env.API}}/avatars/browsers/{{session.clientCode|lowercase}}?width=120&height=120&project={{env.PROJECT}},title={{session.clientName}},alt={{session.clientName}}" class="avatar" loading="lazy" width="60" height="60" data-ls-if="{{session.clientCode|lowercase}} !== 'cli'"/>

                            <img onerror="this.onerror=null;this.className='avatar hide'" data-ls-attrs="src=/images/clients/terminal.png?buster=<?php echo APP_CACHE_BUSTER; ?>,title={{session.clientName}},alt={{session.clientName}}" class="avatar" loading="lazy" width="60" height="60" data-ls-if="{{session.clientCode|lowercase}} === 'cli'" >

                            <div data-ls-if="{{session.provider}} !== 'email'" class="corner">
                                <img data-ls-attrs="src=/images/users/{{session.provider}}.png?buster=<?php echo APP_CACHE_BUSTER; ?>,title={{session.provider}},alt={{session.provider}}"  class="avatar xs" loading="lazy" width="30" height="30" />
                            </div>
                        </div>

                        <span data-ls-if="(!{{log.clientName}})">Unknown</span>
                        <span data-ls-if="({{log.clientName}})" data-ls-bind="{{session.clientName}}"></span> <span data-ls-bind="{{session.clientVersion}}"></span> on <span data-ls-bind="{{session.deviceModel}}"></span> <span data-ls-bind="{{session.osName}}"></span> <span data-ls-bind="{{session.osVersion}}"></span>
                        &nbsp;
                        <span data-ls-if="true == {{session.current}}">
                            <span class="tag green">Current Session</span>
                        </span>

                        <div class="margin-top-small">
                            <img onerror="this.onerror=null;this.className='avatar hide'" data-ls-if="{{session.countryCode}} !== '--'" data-ls-attrs="src={{env.API}}/avatars/flags/{{session.countryCode}}?width=80&height=80&project={{env.PROJECT}}" class="avatar xxs margin-end-small inline" />
                            <small data-ls-bind="{{session.ip}}"></small> / <small data-ls-bind="{{session.countryName}}"></small>
                        </div>
                    </li>
                </ul>
            </div>

            <form class="inline margin-bottom-large"
                data-analytics
                data-analytics-activity
                data-analytics-event="submit"
                data-analytics-category="console"
                data-analytics-label="Delete Account Sessions"
                data-service="account.deleteSessions"
                data-scope="console"
                data-event="submit"
                data-success="trigger,redirect"
                data-success-param-trigger-events="account.deleteSession"
                data-success-param-redirect-url="/"
                data-failure="alert"
                data-failure-param-alert-text="Logout from All Sessions Failed"
                data-failure-param-alert-classname="error">
                <input type="hidden" name="id" value="0">
                <button class="danger">Logout from all sessions</button>
            </form>
        </li>
        <li data-state="/console/account/activity">
            <h2>Activity</h2>

            <div
                data-service="account.getLogs"
                data-scope="console"
                data-name="securityLogs"
                data-event="load">

                <div class="box margin-bottom">
                    <table class="vertical small">
                        <thead>
                            <tr>
                                <th width="120">Date</th>
                                <th width="175">Event</th>
                                <th>Client</th>
                                <th width="110">Location</th>
                                <th width="90">IP</th>
                            </tr>
                        </thead>
                        <tbody data-ls-loop="securityLogs.logs" data-ls-as="log">
                            <tr>
                                <td data-title="Date: "><span data-ls-bind="{{log.time|dateTime}}"></span></td>
                                <td data-title="Event: "><span data-ls-bind="{{log.event}}"></span></td>
                                <td data-title="Client: ">
                                    <img onerror="this.onerror=null;this.className='avatar hide'" data-ls-attrs="src={{env.API}}/avatars/browsers/{{log.clientCode|lowercase}}?width=80&height=80&project={{env.PROJECT}},title={{log.clientName}},alt={{log.clientName}}" class="avatar xxs inline margin-end-small" data-ls-if="{{log.clientCode|lowercase}} !== 'cli'"/>
                                        
                                    <img onerror="this.onerror=null;this.className='avatar hide'" data-ls-attrs="src=/images/clients/terminal.png?buster=<?php echo APP_CACHE_BUSTER; ?>,title={{log.clientName}},alt={{log.clientName}}" class="avatar xxs inline margin-end-small" data-ls-if="{{log.clientCode|lowercase}} === 'cli'" />

                                    <span data-ls-if="(!{{log.clientName}})">Unknown</span>
                                    <span data-ls-if="({{log.clientName}})" data-ls-bind="{{log.clientName}} {{log.clientVersion}} on {{log.model}} {{log.osName}} {{log.osVersion}}"></span>
                                </td>
                                <td data-title="Location: ">
                                    <img onerror="this.onerror=null;this.className='avatar xxs hide'" data-ls-attrs="src={{env.API}}/avatars/flags/{{log.countryCode}}?width=80&height=80&project={{env.PROJECT}}" class="avatar xxs inline margin-end-small" />
                                    <span data-ls-bind="{{log.countryName}}"></span>
                                </td>
                                <td data-title="IP: "><span data-ls-bind="{{log.ip}}"></span></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="pull-end text-align-center paging">
                    <form
                        data-service="account.getLogs"
                        data-event="submit"
                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                        data-param-offset="{{router.params.offset}}"
                        data-scope="console"
                        data-name="securityLogs"
                        data-success="state"
                        data-success-param-state-keys="offset">
                        <button name="offset" data-paging-back data-offset="{{router.params.offset}}" data-total="{{securityLogs.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}} / {{securityLogs.total|pageTotal}}"></span>

                    <form
                        data-service="account.getLogs"
                        data-event="submit"
                        data-param-limit="<?php echo APP_PAGING_LIMIT; ?>"
                        data-param-offset="{{router.params.offset}}"
                        data-scope="console"
                        data-name="securityLogs"
                        data-success="state"
                        data-success-param-state-keys="offset">
                        <button name="offset" data-paging-next data-offset="{{router.params.offset}}" data-total="{{securityLogs.total}}" class="margin-start round small" aria-label="Next"><i class="icon-right-open"></i></button>
                    </form>
                </div>
            </div>
        </li>
    </ul>
</div>
