<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<div class="row">
	<div class="col-md-7">
		<div class="panel panel-default">
			<div class="panel-heading"><b>⚙️ Setting Telegram (Notifikasi PMG)</b></div>
			<div class="panel-body">

				<?php if ($this->session->flashdata('tg_msg')): ?>
					<div class="alert alert-success"><?php echo $this->session->flashdata('tg_msg'); ?></div>
				<?php endif; ?>
				<?php if ($this->session->flashdata('tg_err')): ?>
					<div class="alert alert-danger"><?php echo $this->session->flashdata('tg_err'); ?></div>
				<?php endif; ?>

				<form method="post" action="<?php echo $save_url; ?>">
					<div class="form-group">
						<label>Token Bot Telegram</label>
						<input type="text" name="bot_token" class="form-control"
							placeholder="contoh: 123456789:AAHxxxx..."
							value="<?php echo htmlspecialchars($bot_token); ?>">
						<small class="text-muted">Token didapat dari <b>@BotFather</b> (perintah /newbot atau /mybots).</small>
					</div>
					<div class="form-group">
						<label>Chat ID Admin</label>
						<input type="text" name="chat_id" class="form-control"
							placeholder="contoh: 123456789"
							value="<?php echo htmlspecialchars($chat_id); ?>">
						<small class="text-muted">Cara lihat chat id: kirim pesan apa saja ke bot Anda, lalu buka
						<b>https://api.telegram.org/bot[TOKEN]/getUpdates</b> di browser.</small>
					</div>
					<button type="submit" class="btn btn-primary">💾 Simpan</button>
					<button type="submit" formaction="<?php echo $test_url; ?>" class="btn btn-success">📨 Tes Kirim</button>
					<a href="<?php echo $back_url; ?>" class="btn btn-default">Kembali</a>
				</form>

				<hr>
				<p><b>Status Webhook:</b>
					<?php echo (strlen($webhook_url) > 0) ? 'terdaftar' : 'belum terdaftar (otomatis di Tahap 4 saat approve Telegram aktif)'; ?>
				</p>
			</div>
		</div>
	</div>

	<div class="col-md-5">
		<div class="panel panel-info">
			<div class="panel-heading"><b>📖 Cara kerja singkat</b></div>
			<div class="panel-body">
				<ol>
					<li><b>Bot</b> = akun Telegram "robot" milik Anda.</li>
					<li><b>Token</b> = kunci rahasia bot.</li>
					<li><b>Chat ID</b> = alamat Telegram admin penerima notifikasi.</li>
					<li>Simpan, lalu klik <b>Tes Kirim</b> → pesan harus masuk ke Telegram Anda.</li>
				</ol>
			</div>
		</div>
	</div>
</div>