// Code generated by templ - DO NOT EDIT.

// templ: version: v0.3.1020
package main

//lint:file-ignore SA4006 This context is only used if a nested component is present.

import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"

// CaptchaWidget renders the self-hosted Cap (trycap.dev) proof-of-work widget.
// When placed inside a <form>, the widget injects a hidden `cap-token` field on
// solve, which the form handler verifies against the instance's redeem endpoint.
//
// Vendored from the CMS built-in blocks.CaptchaWidget (cms/backend/blocks/
// captcha_widget.templ): a standalone wasm plugin cannot import the CMS-internal
// blocks package, but the widget markup is fully static (served from this
// instance's own origin), so it is reproduced here verbatim. Re-copy if the
// upstream widget changes.
func CaptchaWidget() templ.Component {
	return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
		templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
		if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
			return templ_7745c5c3_CtxErr
		}
		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
		if !templ_7745c5c3_IsBuffer {
			defer func() {
				templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
				if templ_7745c5c3_Err == nil {
					templ_7745c5c3_Err = templ_7745c5c3_BufErr
				}
			}()
		}
		ctx = templ.InitializeContext(ctx)
		templ_7745c5c3_Var1 := templ.GetChildren(ctx)
		if templ_7745c5c3_Var1 == nil {
			templ_7745c5c3_Var1 = templ.NopComponent
		}
		ctx = templ.ClearChildren(ctx)
		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<script>\n\t\twindow.CAP_CUSTOM_WASM_URL = \"/assets/captcha/cap_wasm_bg.wasm\";\n\t\twindow.CAP_PAKO_URL = \"/assets/captcha/pako_inflate.min.js\";\n\t</script><cap-widget data-cap-api-endpoint=\"/api/captcha/\" data-cap-worker-count=\"2\"></cap-widget><script src=\"/assets/captcha/cap.min.js\" defer></script><script>\n\t\t(function(){\n\t\t\tvar s = document.currentScript;\n\t\t\tvar form = s && s.closest ? s.closest('form') : null;\n\t\t\tif (!form) return;\n\t\t\t// Reset the widget after each htmx submit so a single-use token that\n\t\t\t// was already spent (verify succeeded, business logic may have failed)\n\t\t\t// is cleared and the visitor can re-solve for a retry.\n\t\t\tform.addEventListener('htmx:afterRequest', function(){\n\t\t\t\tvar w = form.querySelector('cap-widget');\n\t\t\t\tif (w && typeof w.reset === 'function') w.reset();\n\t\t\t});\n\t\t})();\n\t</script>")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		return nil
	})
}

var _ = templruntime.GeneratedTemplate
