---
title: "Latent Trait Analysis (LTA/IRT) Report"
date: "`r Sys.Date()`"
output: 
  html_document:
    theme: flatly
    toc: true
    toc_float: true
params:
  lta_res: NA
  console_out: NA
  ai_summary: ""
---

<style>
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
  
  body, p, table, td, th {
    font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6 !important;
    font-size: 14px;
    color: #333333;
  }
  h1, h2, h3, h4, h5, h6 {
    font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.2;
    font-weight: 600;
    color: #2c3e50;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
  }
  h1 { font-size: 28px; border-bottom: 2px solid #ecf0f1; padding-bottom: 10px; }
  h2 { font-size: 22px; color: #2980b9; }
  h3 { font-size: 18px; color: #34495e; }
</style>

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(mirt)
library(knitr)
library(kableExtra)
```

## Item Parameters (IRT)

```{r}
res <- params$lta_res
if(!is.null(res)){
  cfs <- coef(res, IRTpars = TRUE, simplify = TRUE)
  if(!is.null(cfs$items)){
    item_df <- as.data.frame(cfs$items)
    item_df$Item <- rownames(item_df)
    item_df <- item_df[, c(ncol(item_df), 1:(ncol(item_df)-1))]
    kable(item_df, format = "html", row.names = FALSE, digits = 3) %>% 
      kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
  }
} else {
  cat("No LTA/IRT results available.")
}
```

## Trace Lines Plot

```{r, fig.width=8, fig.height=6}
if(!is.null(res)){
  plot(res, type = "trace")
}
```

## Item Information Plot

```{r, fig.width=8, fig.height=6}
if(!is.null(res)){
  plot(res, type = "info")
}
```

```{r ai-summary, results='asis'}
if (!is.null(params$ai_summary) && params$ai_summary != "") {
  cat("## AI Interpretive Summary\n\n")
  cat("<div style='background-color: #f0f7fb; border-left: 4px solid #3498db; padding: 15px; border-radius: 4px; margin-bottom: 25px;'>\n")
  cat(params$ai_summary)
  cat("\n</div>\n\n")
}
```

## R Console Output

<div style="font-family: Consolas, 'Courier New', monospace; font-size: 10px; white-space: pre-wrap; background-color: #f8f9fa; padding: 10px; border: 1px solid #ccc; border-radius: 4px; line-height: 1.2;">
`r params$console_out`
</div>

## References

* Chalmers, R. P. (2012). mirt: A Multidimensional Item Response Theory Package for the R Environment. *Journal of Statistical Software*, 48(6), 1-29.
* Djidu, H., Retnawati, H., Hadi, S., & Haryanto. (2026). projectLSA: A Shiny application for integrated latent structure analysis. *Applied Psychological Measurement*. https://doi.org/10.1177/01466216261446305
* Djidu, H., Retnawati, H., Hadi, S., & Haryanto. (2026). *projectLSA: R Shiny application for latent structure analysis with a graphical user interface*. https://doi.org/10.32614/CRAN.package.projectLSA. R package.

***
*Generated by projectLSA*
