<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>

<head>
  <title>Masuk <?php echo html_escape($server->sv_nama); ?></title>
  <?php include_once(VIEWPATH . 'includes/head.php'); ?>
</head>

<body>
  <?php include_once(VIEWPATH . 'admin/_navbar.php'); ?>
  <div class="container">
    <ul class="breadcrumb">
      <li><a href="<?php echo site_url(); ?>"><i class="fa fa-home"></i></a></li>
      <li><a href="<?php echo site_url('admin'); ?>">Admin Panel</a></li>
      <li><a href="<?php echo site_url('admin/modules/mbs'); ?>">Multi Biller Solution API</a></li>
      <li class="active"><span><?php echo html_escape($server->sv_nama); ?></span></li>
    </ul>
    <div class="row">
      <div class="col-sm-4 col-md-3">
        <?php echo sidebar_menu($sidebar); ?>
      </div>
      <div class="col-sm-8 col-md-9">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3><a class="pull-right text-danger" title="Hapus Data" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/modules/mbs/delete-data/' . $server->sv_id); ?>"><i class="fa fa-times"></i></a><i class="fa fa-sign-in"></i> Masuk <?php echo html_escape($server->sv_nama); ?></h3>
          </div>
          <div class="panel-body">
            <div class="alert alert-info" style="margin-bottom: 15px"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>Untuk info lebih lanjut silakan hubungi Telegram <a class="alert-link" href="https://t.me/helpdeskMBS " target="_blank">@helpdeskMBS</a> (085336777576 ) atau <a class="alert-link" href="https://t.me/CustomerCareMBS  " target="_blank">@CustomerCareMBS</a> (081556588882).</div>
            <div class="well well-sm">
              <div class="form-group">
                <label>IP Address</label>
                <div class="input-group">
                  <input type="text" id="ipstatis" class="form-control" readonly="readonly" value="<?php echo getHostByName(getHostName()); ?>" />
                  <span class="input-group-addon"><a class="copy" data-id="#ipstatis" data-name="IP Address" href="#" data-toggle="tooltip" data-placement="left" data-title="Copy IP Address"><i class="fa fa-copy"></i></a></span>
                </div>
              </div>
              <div>
                <label>Report URL</label>
                <div class="input-group">
                  <span class="input-group-addon"><a id="gencb" href="#" data-toggle="tooltip" data-placement="right" data-title="Generate Report URL"><i class="fa fa-refresh"></i></a></span>
                  <input type="text" id="webhook" class="form-control" readonly="readonly" value="" />
                  <span class="input-group-addon"><a id="editcb" href="#" data-toggle="tooltip" data-placement="right" data-title="Edit Secret Key"><i class="fa fa-edit"></i></a></span>
                  <span class="input-group-addon"><a class="copy" data-id="#webhook" data-name="Report URL" href="#" data-toggle="tooltip" data-placement="left" data-title="Copy Report URL"><i class="fa fa-copy"></i></a></span>
                </div>
              </div>
              <div style="margin-top: 15px; display: none;" id="editcbLayout">
                <form id="cbForm">
                  <label>Secret Key</label>
                  <div class="input-group">
                    <input type="text" name="secret_key" class="form-control" maxlength="32" />
                    <span class="input-group-btn"><button type="submit" class="btn btn-default"><i class="fa fa-check"></i> Simpan</button></span>
                  </div>
                </form>
              </div>
            </div>
            <?php echo form_open(); ?>
            <div class="form-group">
              <label>User ID</label>
              <input type="text" class="form-control" name="userid" placeholder="ABC1234" value="<?php echo set_value('userid', $api['userid']); ?>" maxlength="255" />
            </div>
            <div class="form-group">
              <label>PIN</label>
              <input type="text" class="form-control" name="pin" value="<?php echo set_value('pin', $api['pin']); ?>" maxlength="16" />
            </div>
            <div class="form-group">
              <label>Password</label>
              <input type="password" class="form-control" name="password" value="<?php echo set_value('password', $api['password']); ?>" maxlength="32" />
            </div>
            <div class="form-group">
              <a data-toggle="collapse" href="#pengaturan-lainnya">Pengaturan lainnya <span class="caret"></span></a>
            </div>
            <div id="pengaturan-lainnya" class="collapse">
              <div class="form-group">
                <label>Timeout</label>
                <div class="input-group">
                  <input type="number" class="form-control" name="timeout" value="<?php echo set_value('timeout', isset($api['timeout']) ? $api['timeout'] : 30); ?>" min="5" max="60" />
                  <span class="input-group-addon">detik</span>
                </div>
              </div>
              <div class="checkbox">
                <label><input type="checkbox" name="switch_to_jabber" value="1" <?php echo (isset($api['switch_to_jabber']) && $api['switch_to_jabber'] ? ' checked="checked"' : ''); ?>> Alihkan sementara ke jalur transaksi <strong>Jabber</strong> jika proses transaksi error atau timeout.</label>
              </div>
              <div class="form-group">
                <label>Minimal waktu pengalihan</label>
                <div class="input-group">
                  <input type="number" class="form-control" name="switch_time" value="<?php echo set_value('switch_time', isset($api['switch_time']) ? $api['switch_time'] : 15); ?>" min="1" max="300" <?php echo (isset($api['switch_to_jabber']) && $api['switch_to_jabber'] ? '' : 'disabled="disabled"'); ?> />
                  <span class="input-group-addon">menit</span>
                </div>
              </div>
            </div>
            <div>
              <button type="submit" class="btn btn-primary" name="submit" value="login"><i class="fa fa-sign-in"></i> Masuk</button>
            </div>
            <?php echo form_close(); ?>
          </div>
        </div>
      </div>
    </div>
  </div>
  <?php include_once(VIEWPATH . 'includes/foot.php'); ?>
  <script>
    $('[name="switch_to_jabber"]').change(function() {
      if (this.checked) {
        $('[name="switch_time"]').removeAttr("disabled");
      } else {
        $('[name="switch_time"]').attr("disabled", "disabled");
      }
    });
    var webhookKey = "<?php echo html_escape($api['webhook_key']); ?>";

    function copyText(text) {
      var aux = document.createElement("input");
      aux.setAttribute("value", text);
      document.body.appendChild(aux);
      aux.select();
      document.execCommand("copy");
      document.body.removeChild(aux);
    }
    $('#gencb').click(function() {
      if (confirm("Apakah kamu yakin ingin merubah Report URL?")) {
        $.get("<?php echo site_url('admin/modules/mbs/login/' . $server->sv_id . '/webhook-key'); ?>", function(data) {
          webhookKey = data;
          setReportURL();
          $.notify("Report URL berhasil diubah", "success");
        });
      }
      return false;
    });

    function setReportURL() {
      $("#webhook").val('<?php echo site_url('api/mbs-report/index'); ?>/' + webhookKey);
      $("#editcbLayout").hide();
    }
    $('.copy').click(function() {
      copyText($($(this).data('id')).val());
      $.notify($(this).data('name') + " disalin", "success");
      return false;
    });
    $("#editcb").click(function() {
      $("#editcbLayout").toggle();
      $('[name="secret_key"]').val(webhookKey);
      return false;
    });
    $('#cbForm').submit(function() {
      $.get("<?php echo site_url('admin/modules/mbs/login/' . $server->sv_id . '/webhook-key'); ?>/" + $('[name="secret_key"]').val(), function(data) {
        $.notify("Report URL berhasil diubah", "success");
        webhookKey = data;
        setReportURL();
      });
      return false;
    })
    setReportURL();
  </script>
</body>

</html>