---
title: "Exploratory Factor Analysis (EFA) Report"
date: "`r Sys.Date()`"
output: 
  html_document:
    theme: flatly
    toc: true
    toc_float: true
params:
  efa_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(psych)
library(knitr)
library(kableExtra)
```

## EFA Factor Loadings

```{r}
res <- params$efa_res
if(!is.null(res) && !is.null(res$fa)){
  load_tab <- as.data.frame(round(res$fa$loadings[, ], 3))
  load_tab$Item <- rownames(res$fa$loadings)
  load_tab <- load_tab[, c(ncol(load_tab), 1:(ncol(load_tab)-1))]
  
  kable(load_tab, format = "html", row.names = FALSE) %>% 
    kable_styling(bootstrap_options = c("striped", "hover"), full_width = FALSE)
} else {
  cat("No EFA results available.")
}
```

## Factor Diagram

```{r, fig.width=8, fig.height=6}
if(!is.null(res) && !is.null(res$fa)){
  psych::fa.diagram(res$fa)
}
```

```{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

* 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.
* Revelle, W. (2023). *psych: Procedures for Psychological, Psychometric, and Personality Research*. Northwestern University.

***
*Generated by projectLSA*
