// Mock data for demo
const mockResponses = {
user: [
"Based on your situation, I recommend consulting with a property lawyer.",
"You may be eligible for legal aid. Here are the steps to apply...",
"This falls under consumer protection law. Your rights include...",
"For employment disputes, you should first try mediation..."
],
ngo: [
"Case #123 has been assigned to Advocate Sarah Smith.",
"Documentation received. Scheduling initial consultation.",
"Follow-up required for Case #456. Contacting the client.",
"New case registered. Priority: High. Category: Family Law"
],
advocate: [
"Reviewing case documents. Initial assessment: Strong merit.",
"Court date scheduled for Case #789. Preparing arguments.",
"Settlement offer received. Analyzing terms...",
"Case strategy updated. Recommending alternative dispute resolution."
]
};
// Helper function to get random response
function getRandomResponse(role) {
const responses = mockResponses[role];
return responses[Math.floor(Math.random() * responses.length)];
}
// Helper function to format timestamp
function formatTime(date) {
return new Intl.DateTimeFormat('en-US', {
hour: '2-digit',
minute: '2-digit'
}).format(date);
}
// Main app class
class LegalChatApp {
constructor() {
this.currentRole = 'user';
this.messages = [];
this.responses = {
user: [
"Based on your situation, here are your legal rights:\n\n1. Right to proper notice (usually 30 days)\n2. Right to return of security deposit within 21 days\n3. Right to habitable living conditions\n\nNext steps:\n1. Document all communications with your landlord\n2. Send a formal written notice\n3. Consider consulting with a tenant rights organization\n\nRemember to keep copies of all correspondence and take photos if relevant.",
"Here's what you need to know about filing a police complaint:\n\n1. Visit your local police station\n2. Bring identification and any evidence\n3. Ask for a copy of the FIR (First Information Report)\n\nImportant tips:\n• Write down details while they're fresh in your memory\n• Get contact information of any witnesses\n• Keep a copy of the FIR number\n\nNote: You have the right to get a free copy of the FIR.",
"Regarding workplace discrimination, you have these protections:\n\n1. Protection against unfair termination\n2. Right to equal pay for equal work\n3. Protection against harassment\n\nDocuments to maintain:\n• Employment contract\n• Performance reviews\n• Any discriminatory incidents (date, time, witnesses)\n\nConsider filing a complaint with the labor department.",
"For your consumer rights issue:\n\n1. You're entitled to:\n • Refund for defective products\n • Service as advertised\n • Clear billing information\n\n2. Steps to take:\n • Document the issue\n • File formal complaint\n • Contact consumer protection\n\nKeep all receipts and correspondence for your records."
],
ngo: [
"Case Protocol for Domestic Violence:\n\n1. Immediate Actions:\n • Safety assessment\n • Emergency contacts provided\n • Safe house coordination if needed\n\n2. Documentation Required:\n • Incident reports\n • Medical records (if applicable)\n • Photographic evidence\n • Witness statements\n\n3. Support Services:\n • Counseling referral\n • Legal aid connection\n • Child protection if needed",
"Legal Aid Process:\n\n1. Initial Assessment:\n • Income verification\n • Case merit evaluation\n • Urgency determination\n\n2. Required Documents:\n • Identity proof\n • Income certificate\n • Case-related documents\n\n3. Next Steps:\n • Lawyer assignment\n • Court fee waiver\n • Case filing support",
"Labor Rights Violation Documentation:\n\n1. Evidence Collection:\n • Pay slips\n • Work schedules\n • Communication records\n • Witness statements\n\n2. Case Building:\n • Timeline creation\n • Impact assessment\n • Rights violation mapping\n\n3. Action Plan:\n • Mediation attempt\n • Legal notice drafting\n • Court filing preparation",
"Sensitive Case Management:\n\n1. Privacy Protocols:\n • Data encryption\n • Anonymous reporting\n • Secure file storage\n\n2. Victim Support:\n • Trauma counseling\n • Protection services\n • Medical assistance\n\n3. Case Progression:\n • Regular updates\n • Safety monitoring\n • Support coordination"
],
advocate: [
"Workplace Discrimination Analysis:\n\n1. Legal Framework:\n • Employment Act Sections 2(4), 3(1)\n • Recent Supreme Court Judgment (2023)\n • Workplace Rights Act\n\n2. Relevant Precedents:\n • Smith vs. Corp Ltd (2022) - Similar facts\n • Johnson Case (2021) - Compensation benchmark\n\n3. Strategy Recommendation:\n • Evidence collection focus\n • Mediation first approach\n • Court filing preparation",
"Property Dispute Framework:\n\n1. Applicable Laws:\n • Property Rights Act\n • Urban Land Ceiling Act\n • Recent amendments (2023)\n\n2. Documentation Required:\n • Title deeds\n • Survey reports\n • Tax records\n • Communication records\n\n3. Legal Strategy:\n • Title verification\n • Negotiation phase\n • Court procedure",
"Tenant Rights Analysis:\n\n1. Recent Judgments:\n • High Court Order 2023\n • Rent Control Act updates\n • New protection measures\n\n2. Case Strategy:\n • Notice requirements\n • Deposit regulations\n • Maintenance obligations\n\n3. Documentation Needs:\n • Rental agreement\n • Payment history\n • Correspondence records",
"Court Filing Requirements:\n\n1. Essential Documents:\n • Cause of action proof\n • Supporting evidence\n • Witness statements\n\n2. Procedural Steps:\n • Jurisdiction verification\n • Court fee calculation\n • Service requirements\n\n3. Timeline Management:\n • Filing deadlines\n • Hearing schedules\n • Appeal periods"
]
};
this.initializeApp();
}
initializeApp() {
// Get DOM elements
this.roleSelection = document.getElementById('roleSelection');
this.chatInterface = document.getElementById('chatInterface');
this.messagesDiv = document.getElementById('messages');
this.messageInput = document.getElementById('messageInput');
this.sendButton = document.getElementById('sendButton');
this.backButton = document.getElementById('backButton');
this.userButton = document.getElementById('userRole');
this.ngoButton = document.getElementById('ngoRole');
this.advocateButton = document.getElementById('advocateRole');
// Attach event listeners for role selection
document.querySelectorAll('.role-btn').forEach(button => {
button.addEventListener('click', () => {
const role = button.dataset.role;
this.selectRole(role);
});
});
// Attach chat interface event listeners
this.attachEventListeners();
}
selectRole(role) {
this.currentRole = role;
this.messages = []; // Clear messages when changing roles
this.messagesDiv.innerHTML = ''; // Clear messages display
// Hide role selection and show chat interface
this.roleSelection.classList.add('hidden');
this.chatInterface.classList.remove('hidden');
// Update role buttons
[this.userButton, this.ngoButton, this.advocateButton].forEach(button => {
button.className = "px-4 py-2 rounded-lg bg-dark-700 text-gray-300 hover:bg-dark-600 transition-colors";
});
const activeButton = {
'user': this.userButton,
'ngo': this.ngoButton,
'advocate': this.advocateButton
}[role];
activeButton.className = "px-4 py-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700 transition-colors";
// Add welcome message with example questions
const welcomeMessages = {
user: `Welcome to Legal Chat! I'm here to help you understand your legal rights and options. Here are some examples of questions you can ask:
1. "What are my rights as a tenant?"
2. "How do I file a police complaint?"
3. "What should I do if I face workplace discrimination?"
4. "What are my consumer rights for a defective product?"
Please feel free to ask any legal question you have.`,
ngo: `Welcome to the NGO Worker portal. I can help you with case management and documentation. Here are examples of what you can ask:
1. "How do I document a domestic violence case?"
2. "What's the process for filing legal aid applications?"
3. "How should I handle sensitive case information?"
4. "What documents are needed for labor rights violations?"
Feel free to ask about case protocols and documentation requirements.`,
advocate: `Welcome to the legal professional interface. I can provide case law analysis and procedural guidance. Here are examples of what you can ask:
1. "What are the recent judgments on workplace discrimination?"
2. "How do I structure a property dispute case?"
3. "What are the documentation requirements for court filing?"
4. "What are the key points of tenant protection laws?"
Feel free to ask about legal frameworks and case strategies.`
};
this.addMessage(welcomeMessages[role], false);
}
attachEventListeners() {
this.sendButton.addEventListener('click', () => this.sendMessage());
this.messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.sendMessage();
});
this.backButton.addEventListener('click', () => this.showRoleSelection());
this.userButton.addEventListener('click', () => this.switchRole('user'));
this.ngoButton.addEventListener('click', () => this.switchRole('ngo'));
this.advocateButton.addEventListener('click', () => this.switchRole('advocate'));
}
showRoleSelection() {
// Hide chat interface and show role selection
this.chatInterface.classList.add('hidden');
this.roleSelection.classList.remove('hidden');
// Clear messages when going back to role selection
this.messages = [];
this.messagesDiv.innerHTML = '';
}
switchRole(role) {
this.currentRole = role;
// Clear messages when switching roles
this.messages = [];
this.messagesDiv.innerHTML = '';
[this.userButton, this.ngoButton, this.advocateButton].forEach(button => {
button.className = "px-4 py-2 rounded-lg bg-dark-700 text-gray-300 hover:bg-dark-600 transition-colors";
});
const activeButton = {
'user': this.userButton,
'ngo': this.ngoButton,
'advocate': this.advocateButton
}[role];
activeButton.className = "px-4 py-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700 transition-colors";
const switchMessages = {
user: "Switched to User mode. How can I help you with your legal concerns?",
ngo: "Switched to NGO Worker mode. How can I assist with case management?",
advocate: "Switched to Advocate mode. What legal guidance do you need?"
};
this.addMessage(switchMessages[role], false);
}
getRandomResponse() {
const responses = this.responses[this.currentRole];
return responses[Math.floor(Math.random() * responses.length)];
}
formatTime() {
return new Date().toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit'
});
}
addMessage(text, isUser = true) {
const message = {
text,
isUser,
time: this.formatTime()
};
this.messages.push(message);
this.renderMessage(message);
this.scrollToBottom();
}
renderMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.className = `flex ${message.isUser ? 'justify-end' : 'justify-start'} mb-4`;
const textWithLineBreaks = message.text.replace(/\n/g, '<br>');
messageDiv.innerHTML = `
<div class="${message.isUser ? 'bg-blue-600' : 'bg-dark-800'}
rounded-xl px-4 py-2 max-w-[80%] shadow-lg ${message.isUser ? 'shadow-blue-500/10' : 'shadow-dark-500/10'}">
<p class="text-sm whitespace-pre-wrap">${textWithLineBreaks}</p>
<p class="text-xs mt-1 ${message.isUser ? 'text-blue-200' : 'text-gray-400'}">${message.time}</p>
</div>
`;
this.messagesDiv.appendChild(messageDiv);
}
scrollToBottom() {
this.messagesDiv.scrollTop = this.messagesDiv.scrollHeight;
}
sendMessage() {
const text = this.messageInput.value.trim();
if (!text) return;
this.addMessage(text, true);
this.messageInput.value = '';
setTimeout(() => {
this.addMessage(this.getRandomResponse(), false);
}, 1000);
}
}
// Initialize app when document is ready
document.addEventListener('DOMContentLoaded', () => {
new LegalChatApp();
});