'use client';
import { useEffect, useState, useMemo } from 'react';
import { Button } from '@/components/ui/button';
import { ArrowRight, Sparkles, BookOpen, Shield, Check, FileText, FileSearch } from 'lucide-react';
import { useNavigation } from '@/lib/navigation';
import { usePersona } from '@/components/onboarding/usePersona';
import type { DashboardStats } from '@/lib/types';
const TYPEWRITER_QUESTIONS = [
'ลูกจ้างขาดงาน 3 วันติดต่อกัน เลิกจ้างได้ไหม?',
'ค่าจ้างล่วงเวลาคำนวณอย่างไร?',
'พนักงานทดลองงาน 119 วัน เลิกจ้างต้องจ่ายค่าชดเชยไหม?',
'ลูกจ้างเอาข้อมูลลูกค้าไปให้คู่แข่ง ฟ้องอาญาได้ไหม?',
'ลดค่าจ้างเพราะบริษัทขาดทุน ต้องขอความยินยอมไหม?',
'นายจ้างหยุดกิจการ ต้องจ่ายค่าชดเชยอย่างไร?',
'ลูกจ้างลาป่วยเกิน 30 วัน หักเงินเดือนได้ไหม?',
'รถร่วมเป็นลูกจ้างหรือไม่ ต้องจ่ายค่าชดเชยไหม?',
'ลูกจ้างเมาแล้วขับรถบรรทุก ฟ้องไล่ออกได้ไหม?',
'พนักงานลาออกแล้วฟ้องเรียก OT ย้อนหลัง ต้องจ่ายไหม?',
];
const EMPLOYER_DEFENSE_CARDS = [
{ t: 'เลิกจ้างโดยไม่ต้องจ่ายค่าชดเชย', d: 'มาตรา 119 · 6 กรณีที่เลิกจ้างได้ทันที', ref: 'พ.ร.บ.แรงงาน' },
{ t: 'หนังสือเตือน 3 ครั้ง = เลิกจ้างได้', d: 'วิธีเขียนให้ศาลรับฟังได้', ref: 'ฎีกา 2567/8103' },
{ t: 'ทดลองงาน 119 วัน', d: 'เลิกจ้างก่อนครบ 120 วัน = ไม่ต้องชดเชย', ref: 'มาตรา 118' },
{ t: 'ลูกจ้างเอาข้อมูลไปให้คู่แข่ง', d: 'ฟ้องอาญา + เรียกค่าเสียหาย', ref: 'ป.อ. 323 + NDA' },
{ t: 'ลาป่วยเท็จ / เกินสิทธิ', d: 'ตรวจใบรับรองแพทย์ · หักค่าจ้างได้', ref: 'มาตรา 32' },
{ t: 'ฟ้องเรียก OT ย้อนหลัง', d: 'อายุความ 2 ปี · ต้องมีหลักฐาน', ref: 'มาตรา 193/34' },
];
export function Hero({ stats }: { readonly stats: DashboardStats | null }) {
const { navigate } = useNavigation();
const { persona } = usePersona();
// Persona-aware question pool — fall back to defaults if no persona
const questions = useMemo(() => {
if (persona && persona.sampleQuestions.length >= 3) return persona.sampleQuestions;
return TYPEWRITER_QUESTIONS;
}, [persona]);
const [typedQ, setTypedQ] = useState('');
const [startIdx] = useState(() => {
// Cryptographically secure random — satisfies SonarCloud S2245
const arr = new Uint8Array(1);
crypto.getRandomValues(arr);
return arr[0] % questions.length;
});
const [qIdx, setQIdx] = useState(startIdx);
// Reset qIdx if questions array changes (persona switch)
useEffect(() => {
if (qIdx >= questions.length) setQIdx(0);
}, [questions, qIdx]);
// Typewriter effect — cycle through example questions (randomized start)
useEffect(() => {
const q = questions[qIdx];
let i = 0;
setTypedQ('');
const typeInt = setInterval(() => {
i++;
setTypedQ(q.slice(0, i));
if (i >= q.length) {
clearInterval(typeInt);
setTimeout(() => setQIdx((qIdx + 1) % questions.length), 4000);
}
}, 120);
return () => clearInterval(typeInt);
}, [qIdx]);
return (
<>
{/* Decorative glow + floating mascot */}
{/* Floating mascot — large, semi-transparent */}
{/* Badge */}
AI ที่ยืนข้างนายจ้าง · Employer-Side Legal AI
{/* Headline */}
ที่สุดแห่งปัญญาประดิษฐ์
ครบเครื่องมือกฎหมายไทย
เพื่อปกป้องบริษัทคุณ
AI ที่ค้นและตอบข้อกฎหมายไทย{' '}
พร้อมอ้างอิงมาตรา ฎีกา และคำพิพากษาศาลจริง{' '}
ครอบคลุมกฎหมายแรงงาน อาญา แพ่ง — ไม่ประดิษฐ์มาตราที่ไม่มีอยู่จริง
{/* CTA */}
{/* Trust chips */}
ข้อมูลจาก law.go.th (กฤษฎีกา)
คำพิพากษาศาลฎีกา 502 คดี
อ้างอิงตรวจสอบได้ทุกคำตอบ
{/* Live chat demo card with typewriter */}
navigate({ name: 'ask' })} />
{/* Stats Strip */}
{stats &&
}
{/* Gold rule */}
{/* 4 Action Buttons — "วันนี้คุณต้องการอะไร?" */}
{/* Employer Section */}
>
);
}
/* ---------- Live Chat Demo (animated preview) ---------- */
function LiveChatDemo({ typedQ, qIdx, onAskClick }: { readonly typedQ: string; readonly qIdx: number; readonly onAskClick: () => void }) {
// Randomize demo content based on typedQ hash
const demoVariants = [
{
verdict: 'เลิกจ้างได้ · ไม่ต้องจ่ายค่าชดเชย',
verdictColor: 'bg-green-500/20 text-green-300',
answer: 'หากลูกจ้างขาดงานติดต่อกันครบ 3 วันทำงานโดยไม่มีเหตุอันสมควร ถือเป็น "การละทิ้งหน้าที่" ตาม',
law: 'พ.ร.บ.คุ้มครองแรงงาน มาตรา 119(5)',
steps: [
{ label: 'ค้นในกฎหมายแรงงาน 2541', done: true },
{ label: 'พบมาตรา 119(5), 118', done: true },
{ label: 'ตรวจสอบคำพิพากษาฎีกา 4 คดี', done: true },
{ label: 'เรียบเรียงคำตอบพร้อมอ้างอิง', done: false },
],
},
{
verdict: 'ต้องจ่าย · 1.5 เท่าค่าจ้างปกติ',
verdictColor: 'bg-blue-500/20 text-blue-300',
answer: 'การทำงานล่วงเวลา นายจ้างต้องจ่ายค่าจ้างไม่น้อยกว่า 1.5 เท่าของอัตราค่าจ้างปกติ สำหรับชั่วโมงแรก และ 3 เท่า สำหรับชั่วโมงถัดไปในวันหยุด ตาม',
law: 'พ.ร.บ.คุ้มครองแรงงาน มาตรา 61',
steps: [
{ label: 'ค้นในกฎหมายแรงงาน 2541', done: true },
{ label: 'พบมาตรา 61, 62 (OT rate)', done: true },
{ label: 'ตรวจอนุบัญญัติค่าจ้าง OT', done: true },
{ label: 'คำนวณอัตราตามประเภทงาน', done: false },
],
},
{
verdict: 'เสี่ยงสูง · ต้องจ่ายค่าชดเชย',
verdictColor: 'bg-red-500/20 text-red-300',
answer: 'การลดค่าจ้างฝ่ายเดียวโดยไม่ได้ความยินยอมจากลูกจ้าง ถือเป็นการเปลี่ยนสภาพการจ้างโดยมิชอบ ตาม',
law: 'พ.ร.บ.คุ้มครองแรงงาน มาตรา 53',
steps: [
{ label: 'ค้นในกฎหมายแรงงาน 2541', done: true },
{ label: 'พบมาตรา 53 (ห้ามลดค่าจ้าง)', done: true },
{ label: 'ตรวจฎีกา 2566/9876', done: true },
{ label: 'ประเมินความเสี่ยงฝั่งนายจ้าง', done: false },
],
},
];
// Use qIdx (question index) for variant — NOT typedQ.length
// This way demo content only changes when the QUESTION changes, not every keystroke
const variantIdx = qIdx % demoVariants.length;
const demo = demoVariants[variantIdx];
return (
{/* Header */}
Panya-AI
● พร้อมตอบ
{[1, 2, 3].map(dotNum => (
))}
{/* Question bubble with typewriter */}
{/* Agent steps preview */}
AI กำลังทำงาน
{demo.steps.map((s, i) => (
))}
{/* Preview answer */}
{demo.verdict}
{demo.answer}
{demo.law}
[1]
{' '}นายจ้างมีสิทธิดำเนินการ...
{/* CTA below demo */}
);
}
/* ---------- Stats Strip ---------- */
function StatsStrip({ stats }: { readonly stats: DashboardStats }) {
const items = [
{ n: '78', label: 'กฎหมายไทยในระบบ', sub: 'แรงงาน · อาญา · แพ่ง · ภาษี' },
{ n: (stats.totalSections || 12936).toLocaleString('th-TH'), label: 'มาตราให้ค้นหา', sub: 'FTS5 + LIKE fallback' },
{ n: (stats.totalLaborJudgments || 502).toLocaleString('th-TH'), label: 'คำพิพากษาฎีกา', sub: 'พร้อมสรุปประเด็น' },
{ n: '63', label: 'เทมเพลตเอกสาร PDF', sub: 'ครอบคลุม 5 หมวด' },
];
return (
{items.map((it, i) => (
{it.n}
{it.label}
{it.sub}
))}
);
}
/* ---------- Employer Section (defense cards) ---------- */
function EmployerSection() {
const { navigate } = useNavigation();
return (
{/* Left: pitch */}
Employer-Side · ฝั่งนายจ้าง
ป้องกันลูกจ้างหัวหมอ
โดยไม่ทำผิดกฎหมาย
AI ทั่วไปตอบเข้าข้างลูกจ้าง — Panya-AI ออกแบบมาเพื่อรู้{' '}
กลอุบายและช่องโหว่{' '}
ที่ลูกจ้างมักใช้ฟ้องนายจ้าง แล้วชี้แนวป้องกันที่
ถูกต้องตามกฎหมาย 100%
{/* Gold rule */}
"รู้กฎ ยิ่งกว่าอีกฝ่าย = ไม่ต้องกลัวถูกฟ้อง"
{/* Right: 6 defense cards */}
{EMPLOYER_DEFENSE_CARDS.map((c, i) => (
0{i + 1}
{c.t}
{c.d}
{c.ref}
))}
);
}
/* ---------- 4 Action Buttons ---------- */
function ActionButtons({ onNav }: { readonly onNav: (v: any) => void }) {
const actions = [
{
label: 'ถาม AI',
desc: 'คำถามกฎหมายแรงงาน พร้อมอ้างอิงมาตรา/ฎีกา',
icon: Sparkles,
view: { name: 'ask' as const },
color: 'from-gold/15 to-gold/5 border-gold/30 hover:border-gold/50',
iconColor: 'text-gold',
},
{
label: 'ตรวจสัญญา',
desc: 'วางข้อความสัญญา → AI หาข้อผิดกฎหมาย',
icon: FileSearch,
view: { name: 'contract-analysis' as const },
color: 'from-red-500/10 to-red-500/5 border-red-500/20 hover:border-red-500/40',
iconColor: 'text-red-500',
},
{
label: 'สร้างเอกสาร',
desc: '63 เทมเพลตพร้อมกรอก + ดาวน์โหลด PDF',
icon: FileText,
view: { name: 'pdf-builder' as const },
color: 'from-blue-500/10 to-blue-500/5 border-blue-500/20 hover:border-blue-500/40',
iconColor: 'text-blue-500',
},
{
label: 'ประเมินความเสี่ยง',
desc: 'Risk Matrix 5×5 สำหรับนายจ้าง',
icon: Shield,
view: { name: 'risk-matrix' as const },
color: 'from-orange-500/10 to-orange-500/5 border-orange-500/20 hover:border-orange-500/40',
iconColor: 'text-orange-500',
},
];
return (
วันนี้คุณต้องการอะไร?
เลือกงานที่ต้องการ — Panya-AI พร้อมช่วยทันที
{actions.map((a) => {
const Icon = a.icon;
return (
);
})}
);
}