<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Candy - Chats are not dead yet</title>
    <link rel="shortcut icon" href="res/img/favicon.png" type="image/gif"/>
    <link rel="stylesheet" type="text/css" href="libs.min.css"/>
    <link rel="stylesheet" type="text/css" href="res/default.css"/>

    <script>delete module.exports</script>
    <script type="text/javascript" src="../node_modules/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="libs.min.js"></script>
    <script type="text/javascript" src="candy.min.js"></script>
    <script type="text/javascript">
        //require('electron').remote.getCurrentWebContents().openDevTools();
        $(document).ready(function () {
            var querystring = require('querystring');
            var params = querystring.parse(location.search.slice(1));

            Candy.View.Template.Login.form = '<form method="post" id="login-form" class="login-form">' + '<input type="hidden" id="nickname" name="nickname" value="' + params.nickname + '"/>' + '{{#displayUsername}}<input type="hidden" id="username" name="username" value="' + params.jid + '"/>' + '{{#displayDomain}} <span class="at-symbol">@</span> ' + '<select id="domain" name="domain">{{#domains}}<option value="{{domain}}">{{domain}}</option>{{/domains}}</select>' + "{{/displayDomain}}" + "{{/displayUsername}}" + '{{#presetJid}}<input type="hidden" id="username" name="username" value="{{presetJid}}"/>{{/presetJid}}' + '{{#displayPassword}}<input type="hidden" id="password" name="password" value="' + params.password + '"/>{{/displayPassword}}' + '<input type="submit" class="button" value="{{_loginSubmit}}" /></form>'

            Candy.Util.setCookie('candy-nostatusmessages', '1', 365);
            Candy.init('wss://chat.mycard.moe:5280/websocket', {
                core: {
                    // only set this to true if developing / debugging errors
                    debug: false,
                    // autojoin is a *required* parameter if you don't have a plugin (e.g. roomPanel) for it
                    //   true
                    //     -> fetch info from server (NOTE: does only work with openfire server)
                    //   ['test@conference.example.com']
                    //     -> array of rooms to join after connecting
                    autojoin: [params.autojoin],
                    resource: 'mycard-' + Math.random().toString().split('.')[1]
                },
                view: {assets: 'res/', language: 'cn'}
            });

            Candy.Core.connect(params.jid, params.password, params.nickname);

            Candy.Core.connect();
            /**
             * Thanks for trying Candy!
             *
             * If you need more information, please see here:
             *   - Setup instructions & config params: http://candy-chat.github.io/candy/#setup
             *   - FAQ & more: https://github.com/candy-chat/candy/wiki
             *
             * Mailinglist for questions:
             *   - http://groups.google.com/group/candy-chat
             *
             * Github issues for bugs:
             *   - https://github.com/candy-chat/candy/issues
             */

            // fix
            Base64.encode = function (input) {
                return new Buffer(input).toString('base64');
            };
            Base64.decode = function (input) {
                return new Buffer(input, 'base64').toString();
            };
        });
    </script>
</head>
<body>
<div id="candy"></div>
</body>
</html>
