$path = "e:\Desktop\CICD\src\shared\i18n\messages\en\lesson-preparation.json"
$content = Get-Content -Raw $path

# Find the final closing brace of the "confirm" object + outer object
$marker = '    "archiveTitle": "Confirm Archive"' + "`r`n" + '  }' + "`r`n" + '}'
$markerLF = '    "archiveTitle": "Confirm Archive"' + "`n" + '  }' + "`n" + '}'

$appendix = @'
  },
  "calendar": {
    "title": "Lesson Plan Calendar",
    "description": "View lesson preparation activities by date",
    "weekView": "Week",
    "monthView": "Month",
    "today": "Today",
    "prev": "Previous",
    "next": "Next",
    "noEvents": "No activities on this day",
    "loading": "Loading...",
    "loadFailed": "Failed to load calendar",
    "eventType": {
      "created": "Created",
      "updated": "Updated",
      "version_saved": "Version Saved",
      "submitted": "Submitted",
      "published": "Published",
      "reviewed": "Reviewed"
    },
    "eventMeta": "v{versionNo}",
    "weekDays": {
      "sun": "Sun",
      "mon": "Mon",
      "tue": "Tue",
      "wed": "Wed",
      "thu": "Thu",
      "fri": "Fri",
      "sat": "Sat"
    }
  },
  "review": {
    "title": "Review Workflow",
    "submit": "Submit for Review",
    "withdraw": "Withdraw Submission",
    "approve": "Approve",
    "reject": "Reject",
    "submitConfirm": "Submit for review? You cannot edit after submission until reviewed.",
    "withdrawConfirm": "Withdraw submission? The plan will return to draft status.",
    "approveConfirm": "Approve this lesson plan?",
    "rejectConfirm": "Reject this lesson plan? The teacher can revise and resubmit.",
    "commentLabel": "Review Comment",
    "commentPlaceholder": "Enter review comment (optional)",
    "submitted": "Submitted for Review",
    "approved": "Approved",
    "rejected": "Rejected",
    "withdrawn": "Withdrawn",
    "reviewerLabel": "Reviewer: {name}",
    "reviewAt": "Reviewed at: {time}",
    "records": "Review Records",
    "noRecords": "No review records",
    "pendingTitle": "Pending Review",
    "pendingEmpty": "No pending reviews",
    "invalidTransition": "Invalid status transition",
    "notSubmitted": "Cannot submit for review in current status",
    "notReviewable": "Cannot review in current status",
    "submitSuccess": "Submitted for review",
    "withdrawSuccess": "Submission withdrawn",
    "approveSuccess": "Approved",
    "rejectSuccess": "Rejected"
  },
  "comment": {
    "title": "Collaboration Comments",
    "add": "Post Comment",
    "reply": "Reply",
    "placeholder": "Enter comment...",
    "empty": "No comments",
    "resolve": "Mark as Resolved",
    "reopen": "Reopen",
    "resolved": "Resolved",
    "unresolved": "Unresolved",
    "delete": "Delete",
    "deleteConfirm": "Delete this comment? Replies will also be deleted.",
    "edit": "Edit",
    "unresolvedCount": "{count} unresolved",
    "blockLabel": "Block: {title}",
    "createSuccess": "Comment posted",
    "deleteSuccess": "Deleted",
    "resolveSuccess": "Marked as resolved",
    "createFailed": "Failed to post comment",
    "deleteFailed": "Failed to delete comment"
  },
  "formative": {
    "title": "Formative Assessment",
    "add": "Add Interaction",
    "empty": "No interactions",
    "interactionType": {
      "poll": "Poll",
      "quiz": "Quiz",
      "exit_ticket": "Exit Ticket"
    },
    "promptLabel": "Prompt",
    "promptPlaceholder": "Enter prompt...",
    "optionsLabel": "Options",
    "addOption": "+ Add Option",
    "correctAnswer": "Correct Answer",
    "durationLabel": "Duration (sec)",
    "responses": "Student Responses",
    "noResponses": "No responses",
    "stats": "Statistics",
    "totalResponses": "{count} responses",
    "correctRate": "Correct rate {rate}%",
    "avgDuration": "Avg {sec} sec",
    "createSuccess": "Added",
    "updateSuccess": "Updated",
    "deleteSuccess": "Deleted"
  },
  "attachment": {
    "title": "Attachments",
    "add": "Add Attachment",
    "empty": "No attachments",
    "type": {
      "reference": "Reference",
      "material": "Material",
      "supplementary": "Supplementary"
    },
    "nameLabel": "Name",
    "urlLabel": "URL",
    "typeLabel": "Type",
    "createSuccess": "Attachment added",
    "deleteSuccess": "Attachment deleted",
    "updateSuccess": "Attachment updated"
  },
  "substitute": {
    "title": "Substitute Teacher",
    "add": "Add Substitute",
    "empty": "No substitute records",
    "originalTeacher": "Original Teacher",
    "substituteTeacher": "Substitute Teacher",
    "startDate": "Start Date",
    "endDate": "End Date",
    "status": {
      "active": "Active",
      "expired": "Expired",
      "cancelled": "Cancelled"
    },
    "createSuccess": "Substitute arranged",
    "updateSuccess": "Substitute status updated",
    "deleteSuccess": "Substitute deleted",
    "cancelConfirm": "Cancel this substitute arrangement?"
  },
  "evaluation": {
    "title": "AI Evaluation",
    "run": "Run Evaluation",
    "running": "Evaluating...",
    "empty": "No evaluation records",
    "overallScore": "Overall Score",
    "dimensions": {
      "clarity": "Clarity",
      "alignment": "Standards Alignment",
      "engagement": "Engagement",
      "differentiation": "Differentiation",
      "assessment": "Assessment"
    },
    "suggestions": "Suggestions",
    "noSuggestions": "No suggestions",
    "createSuccess": "Evaluation completed",
    "suggestion": {
      "addMoreNodeDetails": "Add more details in teaching nodes",
      "linkMoreStandards": "Link more curriculum standards",
      "addFormativeItems": "Add classroom interactions",
      "addPracticeBlock": "Add practice block",
      "addHomeworkBlock": "Specify homework requirements"
    }
  },
  "analytics": {
    "title": "Analytics",
    "teacherInvestment": "Teacher Investment",
    "templateUsage": "Template Usage",
    "standardsCoverage": "Standards Coverage",
    "globalStats": "Overview",
    "totalTeachers": "Teachers",
    "totalPlans": "Total Plans",
    "totalPublished": "Published",
    "totalSubmitted": "Pending Review",
    "totalStandardsLinked": "Standards Linked",
    "noData": "No data",
    "loadFailed": "Failed to load analytics"
  },
  "standards": {
    "title": "Standards Alignment",
    "link": "Link Standard",
    "unlink": "Unlink",
    "linked": "{count} linked",
    "empty": "No linked standards",
    "searchPlaceholder": "Search standards...",
    "level": {
      "national": "National",
      "curriculum": "Curriculum",
      "custom": "Custom"
    },
    "linkSuccess": "Standard linked",
    "unlinkSuccess": "Standard unlinked"
  }
}
'@

$matched = $false
if ($content.Contains($marker)) {
    $newContent = $content.Replace($marker, '    "archiveTitle": "Confirm Archive"' + "`r`n" + $appendix)
    $matched = $true
    Write-Output "Matched CRLF marker"
} elseif ($content.Contains($markerLF)) {
    $newContent = $content.Replace($markerLF, '    "archiveTitle": "Confirm Archive"' + "`n" + $appendix)
    $matched = $true
    Write-Output "Matched LF marker"
}

if ($matched) {
    Set-Content -Path $path -Value $newContent -NoNewline -Encoding UTF8
    Write-Output "File written successfully. New size: $($newContent.Length)"
} else {
    Write-Output "No marker matched"
    Write-Output "Last 80 chars of content:"
    Write-Output $content.Substring($content.Length - 80)
}
