<?php
/**
 * 芋头CMS - 家具定制企业网站模板 - 留言页
 */
if (!defined('ROOT_PATH')) { exit('Access Denied'); }

$pageTitle = '在线留言';
$extraHead = '<style>.guestbook-page-body { padding-top: 70px; }</style>';

require_once __DIR__ . '/_header.php';
?>

<div class="guestbook-page-body">
<div style="height:280px;background:linear-gradient(135deg,var(--dark) 0%,var(--primary-dark) 100%);display:flex;align-items:center;justify-content:center;margin-top:70px;">
<div style="text-align:center;color:white;">
<h1 style="font-size:36px;margin-bottom:10px;">在线留言</h1>
<p style="opacity:0.7;font-size:14px;">期待您的宝贵建议</p>
</div>
</div>

<section class="guestbook-section section">
<div class="container">
<form class="guestbook-form" id="guestbookForm" method="post" action="/public/guestbook.php">
<input type="hidden" name="ajax" value="1">
<div class="form-row">
<input type="text" name="name" placeholder="您的姓名" required>
<input type="text" name="contact" placeholder="联系电话" required>
</div>
<textarea name="content" placeholder="请输入留言内容..." required></textarea>
<div style="display:flex;justify-content:center;gap:16px;align-items:center;margin-top:4px;">
<button type="submit">提交留言</button>
<span id="guestbookTip"></span>
</div>
</form>
</div>
</section>
</div>

<script>
(function(){
var form = document.getElementById('guestbookForm');
if (form) {
form.addEventListener('submit', function(e){
e.preventDefault();
var fd = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/public/guestbook.php', true);
xhr.onload = function(){
var r;
try { r = JSON.parse(this.responseText); } catch(e) { r = {msg:'提交成功'}; }
var tip = document.getElementById('guestbookTip');
if (r.code == 200) {
form.reset();
tip.style.color = '#16a34a';
tip.textContent = '✅ ' + (r.msg || '提交成功');
} else {
tip.style.color = '#dc2626';
tip.textContent = '❌ ' + (r.msg || '提交失败');
}
};
xhr.send(fd);
});
}
})();
</script>

<?php require_once __DIR__ . '/_footer.php'; ?>