package htmlanalyzer_test

import (
	"context"
	"testing"

	htmlanalyzer "bit.admedia.com/scm/ad/adpilot-indexing-code-parser.com/internal/service/parser/analyzers/html"
)

const vueSFC = `<template><div>{{ msg }}</div></template>
<script setup>
const msg = 'hello'
</script>`

func TestAnalyzerExtractsHTMLStructure(t *testing.T) {
	source := `<html><body><form id="login"><a href="/home">Home</a></form></body></html>`
	a := htmlanalyzer.NewAnalyzer()
	artifact, chunks, err := a.ParseFile(context.Background(), []byte(source), "index.html", "html")
	if err != nil {
		t.Fatalf("ParseFile: %v", err)
	}
	if len(chunks) == 0 {
		t.Fatal("expected chunks")
	}
	if len(artifact.Nodes) < 2 {
		t.Fatal("expected html nodes")
	}
}

func TestAnalyzerDetectsVueSFC(t *testing.T) {
	a := htmlanalyzer.NewAnalyzer()
	artifact, _, err := a.ParseFile(context.Background(), []byte(vueSFC), "src/App.vue", "vue")
	if err != nil {
		t.Fatalf("ParseFile: %v", err)
	}
	found := false
	for _, node := range artifact.Nodes {
		if node.Metadata != nil && node.Metadata["framework"] == "vue" {
			found = true
		}
	}
	if !found {
		t.Fatal("expected vue framework metadata")
	}
}
