joermd commited on
Commit
8c002de
·
verified ·
1 Parent(s): 31dd1d0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +192 -189
index.html CHANGED
@@ -259,7 +259,7 @@
259
  <section id="home" class="section">
260
  <h2 class="text-3xl font-bold text-gray-800 mb-8">الخدمات القانونية</h2>
261
  <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
262
- <!-- بطاقات الخدمة (نفس الشكل كما سابقاً) -->
263
  <div class="feature-card p-6">
264
  <div class="text-center">
265
  <i class="fas fa-balance-scale text-3xl mb-4 text-blue-600"></i>
@@ -323,16 +323,20 @@
323
  </div>
324
  </section>
325
 
326
- <!-- الأقسام الأخرى (التحليل، المستندات، خريطة التفكير، البحث، الترجمة، الاستشارة) -->
 
327
  <section id="analysis" class="section hidden">
328
  <h2 class="text-3xl font-bold text-gray-800 mb-8">التحليل القانوني</h2>
329
  <div class="input-group bg-white rounded p-6 shadow">
 
 
330
  <textarea class="w-full p-3 border rounded" placeholder="اكتب وصف القضية أو المستند الذي تريد تحليله..."></textarea>
331
  <button class="action-button mt-4" onclick="handleSubmit('analysis', 'قم بتحليل هذه القضية: ')">تحليل</button>
332
  <div id="analysisResult" class="mt-4 response-container"></div>
333
  </div>
334
  </section>
335
 
 
336
  <section id="documents" class="section hidden">
337
  <h2 class="text-3xl font-bold text-gray-800 mb-8">إنشاء مستند قانوني</h2>
338
  <div class="input-group bg-white rounded p-6 shadow">
@@ -342,6 +346,7 @@
342
  </div>
343
  </section>
344
 
 
345
  <section id="mindMap" class="section hidden">
346
  <h2 class="text-3xl font-bold text-gray-800 mb-8">خريطة التفكير القانونية</h2>
347
  <div class="input-group bg-white rounded p-6 shadow">
@@ -351,6 +356,7 @@
351
  </div>
352
  </section>
353
 
 
354
  <section id="search" class="section hidden">
355
  <h2 class="text-3xl font-bold text-gray-800 mb-8">البحث القانوني</h2>
356
  <div class="input-group bg-white rounded p-6 shadow">
@@ -360,7 +366,7 @@
360
  </div>
361
  </section>
362
 
363
- <!-- قسم الترجمة القانونية مع إضافة زر تنزيل PDF -->
364
  <section id="translation" class="section hidden">
365
  <h2 class="text-3xl font-bold text-gray-800 mb-8">الترجمة القانونية</h2>
366
  <div class="input-group bg-white rounded p-6 shadow">
@@ -381,6 +387,7 @@
381
  </div>
382
  </section>
383
 
 
384
  <section id="consultation" class="section hidden">
385
  <h2 class="text-3xl font-bold text-gray-800 mb-8">استشارة قانونية</h2>
386
  <div class="input-group bg-white rounded p-6 shadow">
@@ -475,15 +482,42 @@
475
 
476
  <!-- سكربتات الموقع -->
477
  <script>
478
- // تعريف رابط API الخاص بنا
479
  const API_URL = 'https://g2mgow5tgbxsjy-7777.proxy.runpod.net/proxy/8000/chat';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
 
481
  // تفعيل التنقل بين الأقسام
482
  document.querySelectorAll(".nav-link").forEach(link => {
483
  link.addEventListener("click", (e) => {
484
  e.preventDefault();
485
  const section = e.currentTarget.getAttribute("data-section");
486
- showSection(section);
 
 
 
 
 
 
487
  });
488
  });
489
 
@@ -505,7 +539,7 @@
505
  document.querySelector(".sidebar").classList.toggle("open");
506
  });
507
 
508
- // إضافة مستمعي الأحداث لحقول الإدخال لتحسين التأثير عند التركيز
509
  document.querySelectorAll("input, textarea").forEach(element => {
510
  element.addEventListener("focus", function() {
511
  const group = this.closest(".input-group");
@@ -520,45 +554,114 @@
520
  });
521
  });
522
 
523
- // دالة إرسال الطلبات العامة (تحليل، مستند، خريطة، بحث، ترجمة، استشارة)
524
- async function handleSubmit(section, promptPrefix) {
525
- // الحصول على textarea والنتيجة
526
- const textarea = document.querySelector(`#${section} textarea`);
527
- const resultDiv = document.getElementById(`${section}Result`) || document.getElementById(`${section}Result`);
528
- const text = textarea.value.trim();
529
- if (!text) {
530
- alert("الرجاء إدخال نص");
531
- return;
532
- }
533
- const payload = {
534
- message: promptPrefix + text,
535
- history: []
536
- };
537
- try {
538
- // عرض مؤشر التحميل
539
- if(document.getElementById(`${section}Result`))
540
- document.getElementById(`${section}Result`).innerHTML = '<div class="loading-spinner"></div>';
541
- else if(resultDiv)
542
- resultDiv.innerHTML = '<div class="loading-spinner"></div>';
543
- const response = await fetch(API_URL, {
544
- method: "POST",
545
- headers: { "Content-Type": "application/json" },
546
- body: JSON.stringify(payload)
547
- });
548
- if (!response.ok) {
549
- throw new Error("Network response was not ok");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550
  }
551
- const data = await response.json();
552
- if(document.getElementById(`${section}Result`))
553
- document.getElementById(`${section}Result`).innerHTML = data.response || "";
554
- else if(resultDiv)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  resultDiv.innerHTML = data.response || "";
556
- } catch (error) {
557
- console.error("Error:", error);
558
- if(document.getElementById(`${section}Result`))
559
- document.getElementById(`${section}Result`).innerHTML = '<div class="text-red-500">حدث خطأ. يرجى المحاولة مرة أخرى.</div>';
560
- else if(resultDiv)
561
  resultDiv.innerHTML = '<div class="text-red-500">حدث خطأ. يرجى المحاولة مرة أخرى.</div>';
 
562
  }
563
  }
564
 
@@ -576,11 +679,11 @@
576
  // وظيفة إظهار رسالة النجاح عند النسخ
577
  function showSuccessMessage(message) {
578
  const successMessage = document.createElement("div");
579
- successMessage.className = "success-message animate__animated animate__fadeIn";
580
  successMessage.textContent = message;
581
  document.body.appendChild(successMessage);
582
  setTimeout(() => {
583
- successMessage.classList.add("animate__fadeOut");
584
  setTimeout(() => successMessage.remove(), 300);
585
  }, 2000);
586
  }
@@ -595,150 +698,7 @@
595
  });
596
  });
597
 
598
- // دالة الحصول على تسمية الحقل لعرضها في رسائل الخطأ
599
- function getFieldLabel(field) {
600
- const labels = {
601
- contractTitle: 'عنوان العقد',
602
- contractDate: 'تاريخ العقد',
603
- firstPartyName: 'اسم الطرف الأول',
604
- firstPartyID: 'الرقم القومي للطرف الأول',
605
- firstPartyTitle: 'صفة الطرف الأول',
606
- firstPartyNationality: 'جنسية الطرف الأول',
607
- firstPartyAddress: 'عنوان الطرف الأول',
608
- secondPartyName: 'اسم الطرف الثاني',
609
- secondPartyID: 'الرقم القومي للطرف الثاني',
610
- secondPartyTitle: 'صفة الطرف الثاني',
611
- secondPartyNationality: 'جنسية الطرف الثاني',
612
- secondPartyAddress: 'عنوان الطرف الثاني',
613
- contractPreamble: 'البند التمهيدي',
614
- contractTerms: 'بنود العقد'
615
- };
616
- return labels[field] || field;
617
- }
618
-
619
- // وظيفة زر إنشاء العقد
620
- document.getElementById("generateButton").addEventListener("click", async function() {
621
- const button = this;
622
- const outputDiv = document.getElementById("contractOutput");
623
-
624
- // جمع بيانات النموذج
625
- const formData = {
626
- contractTitle: document.getElementById("contractTitle").value.trim(),
627
- contractDate: document.getElementById("contractDate").value,
628
- firstPartyName: document.getElementById("firstPartyName").value.trim(),
629
- firstPartyID: document.getElementById("firstPartyID").value.trim(),
630
- firstPartyTitle: document.getElementById("firstPartyTitle").value.trim(),
631
- firstPartyNationality: document.getElementById("firstPartyNationality").value.trim(),
632
- firstPartyAddress: document.getElementById("firstPartyAddress").value.trim(),
633
- secondPartyName: document.getElementById("secondPartyName").value.trim(),
634
- secondPartyID: document.getElementById("secondPartyID").value.trim(),
635
- secondPartyTitle: document.getElementById("secondPartyTitle").value.trim(),
636
- secondPartyNationality: document.getElementById("secondPartyNationality").value.trim(),
637
- secondPartyAddress: document.getElementById("secondPartyAddress").value.trim(),
638
- contractPreamble: document.getElementById("contractPreamble").value.trim(),
639
- contractTerms: document.getElementById("contractTerms").value.trim()
640
- };
641
-
642
- // التحقق من البيانات المطلوبة
643
- const requiredFields = Object.keys(formData);
644
- const missingFields = requiredFields.filter(field => !formData[field]);
645
-
646
- if (missingFields.length > 0) {
647
- outputDiv.innerHTML = `
648
- <div class="text-red-500 font-bold mb-4">يرجى ملء جميع الحقول المطلوبة</div>
649
- <ul class="list-disc list-inside text-red-500">
650
- ${missingFields.map(field => `<li>${getFieldLabel(field)}</li>`).join('')}
651
- </ul>
652
- `;
653
- return;
654
- }
655
-
656
- // تحديث واجهة المستخدم لحالة التحميل
657
- button.textContent = 'جاري إنشاء العقد...';
658
- button.disabled = true;
659
- outputDiv.innerHTML = `
660
- <div class="flex items-center justify-center space-x-4 text-gray-600">
661
- <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
662
- <span>جاري إنشاء العقد باستخدام الذكاء الاصطناعي...</span>
663
- </div>
664
- `;
665
-
666
- try {
667
- // تحويل التاريخ إلى التنسيق العربي
668
- const dateObj = new Date(formData.contractDate);
669
- const arabicDate = new Intl.DateTimeFormat('ar-EG', {
670
- year: 'numeric',
671
- month: 'long',
672
- day: 'numeric'
673
- }).format(dateObj);
674
-
675
- // إنشاء نص الطلب
676
- const prompt = `قم بإنشاء عقد قانوني مصري رسمي باللغة العربية يتضمن البيانات التالية:
677
-
678
- عنوان العقد: ${formData.contractTitle}
679
- تاريخ العقد: ${arabicDate}
680
-
681
- الطرف الأول:
682
- - الاسم: ${formData.firstPartyName}
683
- - الرقم القومي: ${formData.firstPartyID}
684
- - الصفة: ${formData.firstPartyTitle}
685
- - الجنسية: ${formData.firstPartyNationality}
686
- - العنوان: ${formData.firstPartyAddress}
687
-
688
- الطرف الثاني:
689
- - الاسم: ${formData.secondPartyName}
690
- - الرقم القومي: ${formData.secondPartyID}
691
- - الصفة: ${formData.secondPartyTitle}
692
- - الجنسية: ${formData.secondPartyNationality}
693
- - العنوان: ${formData.secondPartyAddress}
694
-
695
- التمهيد:
696
- ${formData.contractPreamble}
697
-
698
- بنود العقد:
699
- ${formData.contractTerms}
700
-
701
- يجب أن يتضمن العقد:
702
- 1. النص القانوني: "وبعد أن أقر طرفي هذا العقد بكامل أهليتهما المعتبرة قانوناً وشرعاً وبخلو إرادتهما من أي عيب من عيوب الإرادة وبأنهما غير ممنوعين من التصرف وغير محجور عليهما لأي سبب من الأسباب وعدم خضوعهم لقانون الحراسات أو الكسب غير المشروع وبخلوهما من كافة الموانع القانونية والشرعية اللازمة للتعاقد اتفقوا على الآتي"
703
- 2. بند حكم التمهيد يوضح أن التمهيد جزء لا يتجزأ من العقد
704
- 3. تنسيق قانوني رسمي
705
- 4. مكان للتوقيع في النهاية مع كتابة "طرف أول" و "طرف ثاني"`;
706
-
707
- // إرسال الطلب إلى API
708
- const response = await fetch(API_URL, {
709
- method: 'POST',
710
- headers: {
711
- 'Content-Type': 'application/json'
712
- },
713
- body: JSON.stringify({
714
- message: prompt,
715
- history: []
716
- })
717
- });
718
-
719
- if (!response.ok) {
720
- throw new Error(`HTTP error! status: ${response.status}`);
721
- }
722
-
723
- const data = await response.json();
724
- outputDiv.innerHTML = `<div dir="rtl" style="white-space: pre-wrap;">${data.response}</div>`;
725
-
726
- } catch (error) {
727
- outputDiv.innerHTML = `
728
- <div class="text-red-600 font-bold">
729
- عذراً، حدث خطأ في إنشاء العقد. يرجى المحاولة مرة أخرى.
730
- <br>
731
- تفاصيل الخطأ: ${error.message}
732
- </div>
733
- `;
734
- console.error('Error:', error);
735
- } finally {
736
- button.textContent = 'إنشاء العقد';
737
- button.disabled = false;
738
- }
739
- });
740
-
741
- // وظيفة تنزيل الترجمة كملف PDF (باستخدام مكتبة jsPDF)
742
  document.getElementById("downloadPDFButton").addEventListener("click", function() {
743
  const { jsPDF } = window.jspdf;
744
  const doc = new jsPDF({ orientation: "portrait", unit: "pt", format: "a4" });
@@ -752,7 +712,50 @@ ${formData.contractTerms}
752
  doc.save("translation.pdf");
753
  });
754
 
755
- // تهيئة الصفحة بالعرض الافتراضي للقسم "home"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
756
  document.addEventListener("DOMContentLoaded", () => {
757
  showSection("home");
758
  });
 
259
  <section id="home" class="section">
260
  <h2 class="text-3xl font-bold text-gray-800 mb-8">الخدمات القانونية</h2>
261
  <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
262
+ <!-- بطاقات الخدمة -->
263
  <div class="feature-card p-6">
264
  <div class="text-center">
265
  <i class="fas fa-balance-scale text-3xl mb-4 text-blue-600"></i>
 
323
  </div>
324
  </section>
325
 
326
+ <!-- الأقسام الأخرى -->
327
+ <!-- قسم التحليل القانوني -->
328
  <section id="analysis" class="section hidden">
329
  <h2 class="text-3xl font-bold text-gray-800 mb-8">التحليل القانوني</h2>
330
  <div class="input-group bg-white rounded p-6 shadow">
331
+ <!-- حقل رفع ملف PDF (اختياري) -->
332
+ <input type="file" id="analysisPDF" accept=".pdf" class="mb-4" />
333
  <textarea class="w-full p-3 border rounded" placeholder="اكتب وصف القضية أو المستند الذي تريد تحليله..."></textarea>
334
  <button class="action-button mt-4" onclick="handleSubmit('analysis', 'قم بتحليل هذه القضية: ')">تحليل</button>
335
  <div id="analysisResult" class="mt-4 response-container"></div>
336
  </div>
337
  </section>
338
 
339
+ <!-- قسم إنشاء المستندات القانونية -->
340
  <section id="documents" class="section hidden">
341
  <h2 class="text-3xl font-bold text-gray-800 mb-8">إنشاء مستند قانوني</h2>
342
  <div class="input-group bg-white rounded p-6 shadow">
 
346
  </div>
347
  </section>
348
 
349
+ <!-- قسم خريطة التفكير القانونية -->
350
  <section id="mindMap" class="section hidden">
351
  <h2 class="text-3xl font-bold text-gray-800 mb-8">خريطة التفكير القانونية</h2>
352
  <div class="input-group bg-white rounded p-6 shadow">
 
356
  </div>
357
  </section>
358
 
359
+ <!-- قسم البحث القانوني -->
360
  <section id="search" class="section hidden">
361
  <h2 class="text-3xl font-bold text-gray-800 mb-8">البحث القانوني</h2>
362
  <div class="input-group bg-white rounded p-6 shadow">
 
366
  </div>
367
  </section>
368
 
369
+ <!-- قسم الترجمة القانونية -->
370
  <section id="translation" class="section hidden">
371
  <h2 class="text-3xl font-bold text-gray-800 mb-8">الترجمة القانونية</h2>
372
  <div class="input-group bg-white rounded p-6 shadow">
 
387
  </div>
388
  </section>
389
 
390
+ <!-- قسم الاستشارة القانونية -->
391
  <section id="consultation" class="section hidden">
392
  <h2 class="text-3xl font-bold text-gray-800 mb-8">استشارة قانونية</h2>
393
  <div class="input-group bg-white rounded p-6 shadow">
 
482
 
483
  <!-- سكربتات الموقع -->
484
  <script>
485
+ // تعريف API الأساسي (نقطة /chat)
486
  const API_URL = 'https://g2mgow5tgbxsjy-7777.proxy.runpod.net/proxy/8000/chat';
487
+ const UPLOAD_URL = 'https://g2mgow5tgbxsjy-7777.proxy.runpod.net/proxy/8000/upload';
488
+
489
+ // دالة الحصول على البادئة (prompt prefix) بناءً على القسم
490
+ function getPromptPrefix(section) {
491
+ switch(section) {
492
+ case 'analysis':
493
+ return 'قم بتحليل هذه القضية: ';
494
+ case 'documents':
495
+ return 'قم بإنشاء مستند قانوني بناءً على الوصف التالي: ';
496
+ case 'mindMap':
497
+ return 'قم بإنشاء خريطة ذهنية لحل القضية باستخدام تقنية تونى بوزان الشهيرة: ';
498
+ case 'search':
499
+ return 'ابحث عن معلومات قانونية حول: [منصات: منصة1، منصة2، منصة3] ';
500
+ case 'translation':
501
+ return 'قم بترجمة هذا النص القانوني: ';
502
+ case 'consultation':
503
+ return 'أحتاج استشارة قانونية في الموضوع التالي: ';
504
+ default:
505
+ return '';
506
+ }
507
+ }
508
 
509
  // تفعيل التنقل بين الأقسام
510
  document.querySelectorAll(".nav-link").forEach(link => {
511
  link.addEventListener("click", (e) => {
512
  e.preventDefault();
513
  const section = e.currentTarget.getAttribute("data-section");
514
+ if(section) {
515
+ showSection(section);
516
+ // إخفاء الشريط الجانبي على الأجهزة المحمولة بعد النقر
517
+ if(window.innerWidth < 768) {
518
+ document.querySelector(".sidebar").classList.remove("open");
519
+ }
520
+ }
521
  });
522
  });
523
 
 
539
  document.querySelector(".sidebar").classList.toggle("open");
540
  });
541
 
542
+ // تحسين تأثير التركيز على حقول الإدخال
543
  document.querySelectorAll("input, textarea").forEach(element => {
544
  element.addEventListener("focus", function() {
545
  const group = this.closest(".input-group");
 
554
  });
555
  });
556
 
557
+ // دالة إرسال الطلبات لكافة الأقسام؛ تأخذ معاملين: القسم و (اختياري) prompt مخصص
558
+ async function handleSubmit(section, customPrompt) {
559
+ const container = document.getElementById(section);
560
+ const resultDiv = container.querySelector(".response-container");
561
+
562
+ // إذا كان القسم "analysis" نتعامل مع احتمال وجود ملف PDF ونص
563
+ if (section === 'analysis') {
564
+ const fileInput = container.querySelector("#analysisPDF");
565
+ const textArea = container.querySelector("textarea");
566
+ const text = textArea.value.trim();
567
+ resultDiv.innerHTML = ''; // مسح النتائج السابقة
568
+
569
+ let filePromise = null, textPromise = null;
570
+
571
+ // إذا تم إرفاق ملف PDF نقوم برفعه وتحليله
572
+ if (fileInput && fileInput.files && fileInput.files.length > 0) {
573
+ const file = fileInput.files[0];
574
+ let formData = new FormData();
575
+ // استخدام المفتاح "files" ليتوافق مع نقطة النهاية في FastAPI
576
+ formData.append("files", file);
577
+ resultDiv.innerHTML += '<div id="fileAnalysisSpinner" class="loading-spinner"></div>';
578
+ filePromise = fetch(UPLOAD_URL, {
579
+ method: "POST",
580
+ body: formData
581
+ })
582
+ .then(response => {
583
+ if (!response.ok) {
584
+ throw new Error("فشل رفع الملف");
585
+ }
586
+ return response.json();
587
+ })
588
+ .then(data => data.response || "تم تحليل الملف بنجاح")
589
+ .catch(error => {
590
+ console.error("File analysis error:", error);
591
+ return '<div class="text-red-500">حدث خطأ في رفع الملف. يرجى المحاولة مرة أخرى.</div>';
592
+ });
593
+ }
594
+
595
+ // إذا وُجد نص للتحليل (سواءً مع الملف أو بدونه)
596
+ if (text) {
597
+ resultDiv.innerHTML += '<div id="textAnalysisSpinner" class="loading-spinner"></div>';
598
+ const payload = {
599
+ message: (customPrompt || getPromptPrefix(section)) + text,
600
+ history: []
601
+ };
602
+ textPromise = fetch(API_URL, {
603
+ method: "POST",
604
+ headers: { "Content-Type": "application/json" },
605
+ body: JSON.stringify(payload)
606
+ })
607
+ .then(response => {
608
+ if (!response.ok) {
609
+ throw new Error("فشل الاستجابة من الخادم");
610
+ }
611
+ return response.json();
612
+ })
613
+ .then(data => data.response || "")
614
+ .catch(error => {
615
+ console.error("Text analysis error:", error);
616
+ return '<div class="text-red-500">حدث خطأ في تحليل النص. يرجى المحاولة مرة أخرى.</div>';
617
+ });
618
+ }
619
+
620
+ // انتظار انتهاء العمليتين (إن وُجدتا)
621
+ const fileResult = filePromise ? await filePromise : null;
622
+ const textResult = textPromise ? await textPromise : null;
623
+
624
+ // عرض النتائج النهائية
625
+ resultDiv.innerHTML = '';
626
+ if (fileResult) {
627
+ resultDiv.innerHTML += `<div><strong>نتيجة تحليل الملف:</strong><br>${fileResult}</div><br>`;
628
+ }
629
+ if (textResult) {
630
+ resultDiv.innerHTML += `<div><strong>نتيجة تحليل النص:</strong><br>${textResult}</div>`;
631
  }
632
+ if (!fileResult && !textResult) {
633
+ alert("الرجاء إدخال نص أو إرفاق ملف PDF");
634
+ return;
635
+ }
636
+ } else {
637
+ // للأقسام الأخرى التي لا تتطلب رفع ملفات
638
+ const textArea = container.querySelector("textarea");
639
+ const text = textArea.value.trim();
640
+ if (!text) {
641
+ alert("الرجاء إدخال نص");
642
+ return;
643
+ }
644
+ const payload = {
645
+ message: (customPrompt || getPromptPrefix(section)) + text,
646
+ history: []
647
+ };
648
+
649
+ resultDiv.innerHTML = '<div class="loading-spinner"></div>';
650
+ try {
651
+ const response = await fetch(API_URL, {
652
+ method: "POST",
653
+ headers: { "Content-Type": "application/json" },
654
+ body: JSON.stringify(payload)
655
+ });
656
+ if (!response.ok) {
657
+ throw new Error("فشل الاستجابة من الخادم");
658
+ }
659
+ const data = await response.json();
660
  resultDiv.innerHTML = data.response || "";
661
+ } catch (error) {
662
+ console.error("Error:", error);
 
 
 
663
  resultDiv.innerHTML = '<div class="text-red-500">حدث خطأ. يرجى المحاولة مرة أخرى.</div>';
664
+ }
665
  }
666
  }
667
 
 
679
  // وظيفة إظهار رسالة النجاح عند النسخ
680
  function showSuccessMessage(message) {
681
  const successMessage = document.createElement("div");
682
+ successMessage.className = "success-message";
683
  successMessage.textContent = message;
684
  document.body.appendChild(successMessage);
685
  setTimeout(() => {
686
+ successMessage.style.opacity = "0";
687
  setTimeout(() => successMessage.remove(), 300);
688
  }, 2000);
689
  }
 
698
  });
699
  });
700
 
701
+ // وظيفة تنزيل الترجمة كملف PDF باستخدام مكتبة jsPDF
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
  document.getElementById("downloadPDFButton").addEventListener("click", function() {
703
  const { jsPDF } = window.jspdf;
704
  const doc = new jsPDF({ orientation: "portrait", unit: "pt", format: "a4" });
 
712
  doc.save("translation.pdf");
713
  });
714
 
715
+ // وظيفة إضافة حقل جديد في قسم خريطة التفكير
716
+ document.getElementById("addMindMapField")?.addEventListener("click", function() {
717
+ const container = document.getElementById("mindMapFields");
718
+ const newFieldDiv = document.createElement("div");
719
+ newFieldDiv.className = "mb-4";
720
+ newFieldDiv.innerHTML = `<label class="block text-gray-700 font-bold mb-2">خط جديد:</label>
721
+ <input type="text" class="w-full p-3 border rounded" placeholder="اكتب فكرة جديدة" />`;
722
+ container.appendChild(newFieldDiv);
723
+ });
724
+
725
+ // دالة إنشاء خريطة التفكير باستخدام الحقول المتعددة
726
+ function handleMindMap() {
727
+ const inputs = document.querySelectorAll("#mindMapFields input");
728
+ let collectedText = "";
729
+ inputs.forEach((input, index) => {
730
+ const value = input.value.trim();
731
+ if(value) {
732
+ collectedText += `الخيط ${index + 1}: ${value}\n`;
733
+ }
734
+ });
735
+ if (!collectedText.trim()) {
736
+ alert("الرجاء إدخال بعض الأفكار لإنشاء خريطة التفكير");
737
+ return;
738
+ }
739
+ const resultDiv = document.getElementById("mindMapResult");
740
+ const prompt = getPromptPrefix("mindMap") + "\n" + collectedText +
741
+ "\nاستخدم منهجيات قوية مثل تحليل SWOT و5 خطوات لتحليل الأسباب الجذرية مع النظر في البدائل القانونية لتنظيم القضية بشكل احترافي.";
742
+ resultDiv.innerHTML = '<div class="loading-spinner"></div>';
743
+ fetch(API_URL, {
744
+ method: "POST",
745
+ headers: { "Content-Type": "application/json" },
746
+ body: JSON.stringify({ message: prompt, history: [] })
747
+ })
748
+ .then(response => response.json())
749
+ .then(data => {
750
+ resultDiv.innerHTML = data.response || "";
751
+ })
752
+ .catch(error => {
753
+ console.error("Error:", error);
754
+ resultDiv.innerHTML = '<div class="text-red-500">حدث خطأ. يرجى المحاولة مرة أخرى.</div>';
755
+ });
756
+ }
757
+
758
+ // تهيئة الصفحة بالقسم الافتراضي "home"
759
  document.addEventListener("DOMContentLoaded", () => {
760
  showSection("home");
761
  });