scanfile/server/web/templui/components/datepicker/date_picker_templ.go
2025-06-03 15:44:56 +02:00

328 lines
22 KiB
Go

// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.865
// templui component datepicker - version: main installed by templui v0.71.0
package datepicker
//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"
import (
"git.jmbit.de/jmb/scanfile/server/web/templui/components/button"
"git.jmbit.de/jmb/scanfile/server/web/templui/components/calendar"
"git.jmbit.de/jmb/scanfile/server/web/templui/components/icon"
"git.jmbit.de/jmb/scanfile/server/web/templui/components/popover"
"git.jmbit.de/jmb/scanfile/server/web/templui/utils"
"time"
)
type Format string
type LocaleTag string
const (
FormatLOCALE_SHORT Format = "locale-short" // Locale-specific short format (e.g., MM/DD/YY or DD.MM.YY)
FormatLOCALE_MEDIUM Format = "locale-medium" // Locale-specific medium format (e.g., Jan 5, 2024 or 5. Jan. 2024)
FormatLOCALE_LONG Format = "locale-long" // Locale-specific long format (e.g., January 5, 2024 or 5. Januar 2024)
FormatLOCALE_FULL Format = "locale-full" // Locale-specific full format (e.g., Monday, January 5, 2024 or Montag, 5. Januar 2024)
)
// Common Locale (BCP 47)
var (
LocaleDefaultTag = LocaleTag("en-US")
LocaleTagChinese = LocaleTag("zh-CN")
LocaleTagFrench = LocaleTag("fr-FR")
LocaleTagGerman = LocaleTag("de-DE")
LocaleTagItalian = LocaleTag("it-IT")
LocaleTagJapanese = LocaleTag("ja-JP")
LocaleTagPortuguese = LocaleTag("pt-PT")
LocaleTagSpanish = LocaleTag("es-ES")
)
type Props struct {
ID string
Class string
Attributes templ.Attributes
Value time.Time
Format Format // Controls the display format using Intl dateStyle options.
LocaleTag LocaleTag // BCP 47 Locale Tag (e.g., "en-US", "es-ES"). Determines language and regional format defaults.
Placeholder string
Disabled bool
Required bool
HasError bool
Name string
}
func DatePicker(props ...Props) 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 = Script().Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var p Props
if len(props) > 0 {
p = props[0]
}
if p.ID == "" {
p.ID = utils.RandomID()
}
if p.Name == "" {
p.Name = p.ID
}
if p.Placeholder == "" {
p.Placeholder = "Select a date"
}
if p.LocaleTag == "" {
p.LocaleTag = LocaleDefaultTag
}
if p.Format == "" {
p.Format = FormatLOCALE_MEDIUM
}
var contentID = p.ID + "-content"
var valuePtr *time.Time
if !p.Value.IsZero() {
valuePtr = &p.Value
}
templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
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_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
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_Var4 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
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)
if p.Placeholder != "" {
var templ_7745c5c3_Var5 = []any{"text-left grow text-muted-foreground"}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var5...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<span data-datepicker-display class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var5).String())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/datepicker/date_picker.templ`, Line: 1, Col: 0}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(p.Placeholder)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/datepicker/date_picker.templ`, Line: 98, Col: 21}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " <span class=\"text-muted-foreground flex items-center ml-2\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = icon.Calendar(icon.Props{Size: 16}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = button.Button(button.Props{
ID: p.ID,
Variant: button.VariantOutline,
Class: utils.TwMerge(
"w-full select-trigger flex items-center justify-between",
utils.If(p.HasError, "border-destructive ring-destructive"),
p.Class,
),
Disabled: p.Disabled,
Attributes: utils.MergeAttributes(p.Attributes, templ.Attributes{
"data-datepicker": "true",
"data-display-format": string(p.Format),
"data-locale-tag": string(p.LocaleTag),
"data-placeholder": p.Placeholder,
}),
}).Render(templ.WithChildren(ctx, templ_7745c5c3_Var4), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = popover.Trigger(popover.TriggerProps{For: contentID}).Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var8 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
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_Err = calendar.Calendar(calendar.Props{
ID: p.ID + "-calendar-instance", // Pass ID for calendar instance
Name: p.Name, // Pass Name for hidden input
LocaleTag: calendar.LocaleTag(p.LocaleTag), // Pass locale tag to calendar
Value: valuePtr, // Pass pointer to value
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = popover.Content(popover.ContentProps{
ID: contentID,
Placement: popover.PlacementBottomStart,
Class: "p-3",
}).Render(templ.WithChildren(ctx, templ_7745c5c3_Var8), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = popover.Popover().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var handle = templ.NewOnceHandle()
func Script() 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_Var9 := templ.GetChildren(ctx)
if templ_7745c5c3_Var9 == nil {
templ_7745c5c3_Var9 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var10 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
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_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<script defer nonce=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(templ.GetNonce(ctx))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `server/web/templui/components/datepicker/date_picker.templ`, Line: 125, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\">\n\t\t\t(function() { // IIFE Start\n\t\t\t\tfunction parseISODate(isoString) {\n\t\t\t\t\tif (!isoString || typeof isoString !== 'string') return null;\n\t\t\t\t\tconst parts = isoString.match(/^(\\d{4})-(\\d{2})-(\\d{2})$/);\n\t\t\t\t\tif (!parts) return null;\n\t\t\t\t\tconst year = parseInt(parts[1], 10);\n\t\t\t\t\tconst month = parseInt(parts[2], 10) - 1; // JS month is 0-indexed\n\t\t\t\t\tconst day = parseInt(parts[3], 10);\n\t\t\t\t\tconst date = new Date(Date.UTC(year, month, day));\n\t\t\t\t\tif (date.getUTCFullYear() === year && date.getUTCMonth() === month && date.getUTCDate() === day) {\n\t\t\t\t\t\treturn date;\n\t\t\t\t\t}\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tfunction formatDateWithIntl(date, format, localeTag) {\n\t\t\t\t\tif (!date || isNaN(date.getTime())) return '';\n\n\t\t\t\t\t// Always use UTC for formatting to avoid timezone shifts\n\t\t\t\t\tlet options = { timeZone: 'UTC' }; \n\t\t\t\t\tswitch(format) {\n\t\t\t\t\t\tcase 'locale-short': \n\t\t\t\t\t\t\toptions.dateStyle = 'short'; \n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'locale-long': \n\t\t\t\t\t\t\toptions.dateStyle = 'long'; \n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'locale-full':\n\t\t\t\t\t\t\toptions.dateStyle = 'full'; \n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'locale-medium': // Default to medium\n\t\t\t\t\t\tdefault: \n\t\t\t\t\t\t\toptions.dateStyle = 'medium'; \n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Explicitly pass the options object with timeZone: 'UTC'\n\t\t\t\t\t\treturn new Intl.DateTimeFormat(localeTag, options).format(date);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tconsole.error(`Error formatting date with Intl (locale: ${localeTag}, format: ${format}, timezone: UTC):`, e);\n\t\t\t\t\t\t// Fallback to locale default medium on error, still using UTC\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst fallbackOptions = { dateStyle: 'medium', timeZone: 'UTC' }; \n\t\t\t\t\t\t\treturn new Intl.DateTimeFormat(localeTag, fallbackOptions).format(date);\n\t\t\t\t\t\t} catch (fallbackError) {\n\t\t\t\t\t\t\tconsole.error(`Error formatting date with fallback Intl (locale: ${localeTag}, timezone: UTC):`, fallbackError);\n\t\t\t\t\t\t\t// Absolute fallback: Format the UTC date parts manually if Intl fails completely\n\t\t\t\t\t\t\tconst year = date.getUTCFullYear();\n\t\t\t\t\t\t\t// getUTCMonth is 0-indexed, add 1 for display\n\t\t\t\t\t\t\tconst month = (date.getUTCMonth() + 1).toString().padStart(2, '0'); \n\t\t\t\t\t\t\tconst day = date.getUTCDate().toString().padStart(2, '0');\n\t\t\t\t\t\t\treturn `${year}-${month}-${day}`; // Simple ISO format as absolute fallback\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfunction initDatePicker(triggerButton) {\n\t\t\t\t\tif (!triggerButton || triggerButton._datePickerInitialized) return;\n\n\t\t\t\t\tconst datePickerID = triggerButton.id;\n\t\t\t\t\tconst displaySpan = triggerButton.querySelector('[data-datepicker-display]');\n\t\t\t\t\tconst calendarInstanceId = datePickerID + '-calendar-instance';\n\t\t\t\t\tconst calendarInstance = document.getElementById(calendarInstanceId);\n\t\t\t\t\tconst calendarHiddenInputId = calendarInstanceId + '-hidden';\n\t\t\t\t\tconst calendarHiddenInput = document.getElementById(calendarHiddenInputId);\n\n\t\t\t\t\t// Fallback to find calendar relatively\n\t\t\t\t\tlet calendar = calendarInstance;\n\t\t\t\t\tlet hiddenInput = calendarHiddenInput;\n\t\t\t\t\t\n\t\t\t\t\tif (!calendarInstance || !calendarHiddenInput) {\n\t\t\t\t\t\tconst popoverContentId = triggerButton.getAttribute('aria-controls');\n\t\t\t\t\t\tconst popoverContent = popoverContentId ? document.getElementById(popoverContentId) : null;\n\t\t\t\t\t\tif (popoverContent) {\n\t\t\t\t\t\t\tif (!calendar) calendar = popoverContent.querySelector('[data-calendar-container]');\n\t\t\t\t\t\t\tif (!hiddenInput) {\n\t\t\t\t\t\t\t\tconst wrapper = popoverContent.querySelector('[data-calendar-wrapper]');\n\t\t\t\t\t\t\t\thiddenInput = wrapper ? wrapper.querySelector('[data-calendar-hidden-input]') : null;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!displaySpan || !calendar || !hiddenInput) {\n\t\t\t\t\t\tconsole.error(\"DatePicker init error: Missing required elements.\", { datePickerID, displaySpan, calendar, hiddenInput });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst displayFormat = triggerButton.dataset.displayFormat || 'locale-medium';\n\t\t\t\t\tconst localeTag = triggerButton.dataset.localeTag || 'en-US';\n\t\t\t\t\tconst placeholder = triggerButton.dataset.placeholder || 'Select a date';\n\n\t\t\t\t\tconst onCalendarSelect = (event) => {\n\t\t\t\t\t\tif (!event.detail || !event.detail.date || !(event.detail.date instanceof Date)) return;\n\t\t\t\t\t\tconst selectedDate = event.detail.date;\n\t\t\t\t\t\tconst displayFormattedValue = formatDateWithIntl(selectedDate, displayFormat, localeTag);\n\t\t\t\t\t\tdisplaySpan.textContent = displayFormattedValue;\n\t\t\t\t\t\tdisplaySpan.classList.remove('text-muted-foreground');\n\t\t\t\t\t\t\n\t\t\t\t\t\t// Find and click the popover trigger to close it\n\t\t\t\t\t\tconst popoverTrigger = triggerButton.closest('[data-popover]')?.querySelector('[data-popover-trigger]');\n\t\t\t\t\t\tif (popoverTrigger instanceof HTMLElement) {\n\t\t\t\t\t\t\tpopoverTrigger.click(); \n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttriggerButton.click(); // Fallback: click the button itself (might not work if inside popover)\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\tconst updateDisplay = () => {\n\t\t\t\t\t\tif (hiddenInput && hiddenInput.value) {\n\t\t\t\t\t\t\tconst initialDate = parseISODate(hiddenInput.value);\n\t\t\t\t\t\t\tif (initialDate) {\n\t\t\t\t\t\t\t\tconst correctlyFormatted = formatDateWithIntl(initialDate, displayFormat, localeTag);\n\t\t\t\t\t\t\t\tif (displaySpan.textContent.trim() !== correctlyFormatted) {\n\t\t\t\t\t\t\t\t\tdisplaySpan.textContent = correctlyFormatted;\n\t\t\t\t\t\t\t\t\tdisplaySpan.classList.remove('text-muted-foreground');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Handle case where hidden input has invalid value\n\t\t\t\t\t\t\t\tdisplaySpan.textContent = placeholder;\n\t\t\t\t\t\t\t\tdisplaySpan.classList.add('text-muted-foreground');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Ensure placeholder is shown if no value\n\t\t\t\t\t\t\tdisplaySpan.textContent = placeholder;\n\t\t\t\t\t\t\tdisplaySpan.classList.add('text-muted-foreground');\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\t\t// Attach listener to the specific calendar instance\n\t\t\t\t\tcalendar.addEventListener('calendar-date-selected', onCalendarSelect);\n\t\t\t\t\t\n\t\t\t\t\tupdateDisplay(); // Initial display update\n\n\t\t\t\t\ttriggerButton._datePickerInitialized = true;\n\n\t\t\t\t\t// Store cleanup function on the button itself\n\t\t\t\t\ttriggerButton._datePickerCleanup = () => {\n\t\t\t\t\t\tif (calendar) {\n\t\t\t\t\t\t\tcalendar.removeEventListener('calendar-date-selected', onCalendarSelect);\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t} \n\n\t\t\t\tfunction initAllComponents(root = document) {\n\t\t\t\t\tif (root instanceof Element && root.matches('[data-datepicker=\"true\"]')) {\n\t\t\t\t\t\tinitDatePicker(root);\n\t\t\t\t\t}\n\t\t\t\t\troot.querySelectorAll('[data-datepicker=\"true\"]').forEach(triggerButton => {\n\t\t\t\t\t\tinitDatePicker(triggerButton);\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst handleHtmxSwap = (event) => {\n\t\t\t\t\tconst target = event.detail.target || event.detail.elt;\n\t\t\t\t\tif (target instanceof Element) {\n\t\t\t\t\t\trequestAnimationFrame(() => initAllComponents(target));\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tinitAllComponents();\n\t\t\t\tdocument.addEventListener('DOMContentLoaded', () => initAllComponents());\n\n\t\t\t\tdocument.body.addEventListener('htmx:beforeSwap', (event) => {\n\t\t\t\t\tlet target = event.detail.target || event.detail.elt;;\n\t\t\t\t\tif (target instanceof Element) {\n\t\t\t\t\t\tconst cleanup = (button) => {\n\t\t\t\t\t\t\tif (button.matches && button.matches('[data-datepicker=\"true\"]')) {\n\t\t\t\t\t\t\t\tif (button._datePickerCleanup) {\n\t\t\t\t\t\t\t\t\tbutton._datePickerCleanup();\n\t\t\t\t\t\t\t\t\tdelete button._datePickerCleanup;\n\t\t\t\t\t\t\t\t\tdelete button._datePickerInitialized;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\t\n\t\t\t\t\t\t// Cleanup the target itself if it's a trigger button\n\t\t\t\t\t\tif (target.matches && target.matches('[data-datepicker=\"true\"]')) {\n\t\t\t\t\t\t\tcleanup(target);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Cleanup trigger buttons within the target\n\t\t\t\t\t\tif (target.querySelectorAll) {\n\t\t\t\t\t\t\ttarget.querySelectorAll('[data-datepicker=\"true\"]').forEach(cleanup);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\n\n\t\t\t\tdocument.body.addEventListener('htmx:afterSwap', handleHtmxSwap);\n\t\t\t\tdocument.body.addEventListener('htmx:oobAfterSwap', handleHtmxSwap);\n\t\t\t})(); // End of IIFE\n\t\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = handle.Once().Render(templ.WithChildren(ctx, templ_7745c5c3_Var10), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
var _ = templruntime.GeneratedTemplate