import React, { useState, useEffect } from "react";
import { motion } from "framer-motion";
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Legend } from "recharts";
import { Users, Activity, Star, MessageCircle } from "lucide-react";
// Corporate Quest — Mira Tutor with Interactive Scenarios Simulation
const INITIAL_PROFILE = {
name: "Arjun Malhotra",
level: 1,
xp: 0,
badges: [],
reputation: 0,
role: "player",
completedLessons: []
};
function useLocalStorageState(key, initial) {
const [state, setState] = useState(() => {
try {
const raw = localStorage.getItem(key);
return raw ? JSON.parse(raw) : initial;
} catch (e) {
return initial;
}
});
useEffect(() => {
try {
localStorage.setItem(key, JSON.stringify(state));
} catch (e) {}
}, [key, state]);
return [state, setState];
}
const DEFAULT_LEVELS = [
{
id: 1,
title: "The Company Awakens",
objective: "Register the company and decide authorized capital.",
rewardXp: 40,
lesson: `Mira's Lesson 1: Company Formation\n\nConcepts Covered:\n- Meaning of Share Capital\n- Authorized, Issued, and Subscribed Capital\n- Types of Shares (Equity & Preference)\n\nCheckpoint Question:\nQ: Which type of share carries voting rights?\nA) Preference Share\nB) Equity Share ✅\n\nScenario: You are forming a new company and must decide authorized capital. Choose your amount and type of shares to see effects on future finances.`
},
{
id: 2,
title: "The Call of Application Money",
objective: "Handle over-subscription and refund.",
rewardXp: 50,
lesson: `Mira's Lesson 2: Share Application\n\nConcepts Covered:\n- Receiving Share Application Money\n- Journal Entries:\n1) Bank A/c Dr To Share Application A/c\n2) Share Application A/c Dr To Share Capital A/c\n- Over-subscription handling, refunds and adjustment\n\nCheckpoint Question:\nQ: What type of account is Share Application A/c before allotment?\nA) Asset\nB) Liability ✅\n\nScenario: Some investors apply for more shares than available. Decide refund or adjustment and watch journal entries update in real-time.`
},
{
id: 3,
title: "The Allotment Adventure",
objective: "Adjust application money with allotment.",
rewardXp: 60,
lesson: `Mira's Lesson 3: Share Allotment\n\nConcepts Covered:\n- Allotment money due and received\n- Calls in arrears and calls in advance\n- Journal Entries:\n1) Share Allotment A/c Dr To Share Capital A/c\n2) Bank A/c Dr To Share Allotment A/c\n3) Calls in arrears treatment\n\nCheckpoint Question:\nQ: If a shareholder fails to pay allotment money, which account is debited?\nA) Calls in Arrears A/c ✅\nB) Share Capital A/c\n\nScenario: Allotment stage where you must accept or reject incomplete payments. Decisions show immediate effect on accounts.`
},
{
id: 4,
title: "The First Call Trial",
objective: "Make the first call and manage unpaid calls.",
rewardXp: 70,
lesson: `Mira's Lesson 4: Calls on Shares\n\nConcepts Covered:\n- First call and final call concepts\n- Calls in arrears, calls in advance\n- Interest on calls in arrears\n- Journal Entries:\n1) Share First Call A/c Dr To Share Capital A/c\n2) Bank A/c Dr To Share First Call A/c\n3) Interest on Calls in Arrears A/c Dr To Income A/c\n\nCheckpoint Question:\nQ: How is interest on calls in arrears treated in books?\nA) Debited to Interest on Calls in Arrears A/c ✅\nB) Credited to Share Capital A/c\n\nScenario: First call issued. Some shareholders default. Choose actions and watch the system calculate interest and update ledgers.`
},
{
id: 5,
title: "The Final Battle: Forfeiture & Reissue",
objective: "Record forfeiture and reissue entries.",
rewardXp: 100,
lesson: `Mira's Lesson 5: Forfeiture & Reissue\n\nConcepts Covered:\n- Conditions for forfeiture of shares\n- Journal entries for forfeiture:\n1) Share Capital A/c Dr To Share Forfeited A/c\n- Reissue of forfeited shares at discount or premium\n- Journal entries for reissue\n\nCheckpoint Question:\nQ: When forfeited shares are reissued at a premium, where is the profit transferred?\nA) Capital Reserve ✅\nB) Share Capital A/c\n\nScenario: Forfeited shares can be reissued. Decide reissue price and see how Capital Reserve and ledgers are updated immediately.`
}
];
export default function CorporateQuestMiraSimulation() {
const [profile, setProfile] = useLocalStorageState("cq_profile_mira_sim_v1", INITIAL_PROFILE);
const [levels, setLevels] = useLocalStorageState("cq_levels_mira_sim_v1", DEFAULT_LEVELS);
const [currentLevelIndex, setCurrentLevelIndex] = useLocalStorageState("cq_lvl_index_mira_sim_v1", 0);
const [players, setPlayers] = useLocalStorageState("cq_players_mira_sim_v1", [INITIAL_PROFILE]);
const [message, setMessage] = useState(null);
const [showTutor, setShowTutor] = useState(true);
const [doubtLog, setDoubtLog] = useLocalStorageState("cq_doubts_mira_sim_v1", []);
const [doubtInput, setDoubtInput] = useState("");
const [doubtReply, setDoubtReply] = useState("");
const [checkpointAnswered, setCheckpointAnswered] = useState(false);
const [scenarioChoice, setScenarioChoice] = useState(null);
const currentLevel = levels[currentLevelIndex];
useEffect(() => {
if (message) {
const t = setTimeout(() => setMessage(null), 4000);
return () => clearTimeout(t);
}
}, [message]);
function completeLesson() {
if (!checkpointAnswered) {
setMessage({ type: "fail", text: "Answer the checkpoint before completing the lesson." });
return;
}
if (!profile.completedLessons.includes(currentLevel.id)) {
setProfile(p => ({ ...p, completedLessons: [...p.completedLessons, currentLevel.id] }));
}
setShowTutor(false);
setCheckpointAnswered(false);
setScenarioChoice(null);
setMessage({ type: "success", text: "Lesson completed. Quiz unlocked!" });
}
function answerCheckpoint(correct) {
if (correct) {
setCheckpointAnswered(true);
setMessage({ type: "success", text: "Checkpoint answered correctly!" });
} else {
setMessage({ type: "fail", text: "Incorrect answer. Review the lesson content." });
}
}
function handleScenario(choice) {
setScenarioChoice(choice);
setMessage({ type: "info", text: `Scenario choice '${choice}' executed. Ledger and outcomes updated.` });
}
function handleQuiz(correct) {
if (correct) {
const newXP = profile.xp + currentLevel.rewardXp;
setProfile(p => ({ ...p, xp: newXP, level: p.level + 1 }));
setPlayers(p => p.map(pl => pl.name === profile.name ? { ...pl, xp: newXP, level: pl.level + 1 } : pl));
setMessage({ type: "success", text: `Level cleared! +${currentLevel.rewardXp} XP` });
if (currentLevelIndex < levels.length - 1) setCurrentLevelIndex(currentLevelIndex + 1);
setShowTutor(true);
} else {
setMessage({ type: "fail", text: "Incorrect — review the concept." });
}
}
function askMiraDoubt() {
if (!doubtInput.trim()) return;
const reply = `Mira explains: Based on your question '${doubtInput}', here is a detailed explanation with examples and accounting treatment...`;
setDoubtReply(reply);
setDoubtLog(log => [...log, { level: currentLevel.id, question: doubtInput, reply }]);
setDoubtInput("");
}
const leaderboard = [...players].sort((a, b) => b.xp - a.xp);
const avgXP = players.reduce((sum, p) => sum + p.xp, 0) / players.length;
const chartData = players.map(p => ({ name: p.name, XP: p.xp, Level: p.level }));
return (
{showTutor ? (
) : (
)}
{/* Doubt Chat */}
{/* Analytics */}
);
}
Corporate Quest — Mira Simulation
Mira’s Lesson: {currentLevel.title}
{currentLevel.lesson}
Quiz: {currentLevel.title}
Ask Mira
Class Leaderboard
{leaderboard.map((p, i) => (
{i === 0 && }
))}
{i + 1}. {p.name}
Level {p.level} | XP {p.xp}
XP Analytics
Class Average XP: {avgXP.toFixed(1)}
Comments
Post a Comment
Share your Any Doubt/query/suggestions/Needs...