behavior BusySubmit
  on submit
    set :submitter to the first <button[type='submit'], input[type='submit']/> in me
    if :submitter is not null
      set :originalHtml to :submitter's innerHTML
      add @disabled to :submitter
      set busyText to me.dataset.busyText
      if busyText is not null and busyText is not ""
        put busyText into :submitter
      end
    end
  end
  on htmx:afterRequest
    -- 요청 종료(성공·실패 모두) 시 버튼을 복구한다. 특히 429 등 에러로 스왑이 일어나지 않으면
    -- 버튼이 비활성/"처리 중" 상태로 멈춰 있으므로 반드시 재활성화·텍스트 원복이 필요하다.
    if :submitter is not null
      remove @disabled from :submitter
      if :originalHtml is not null
        put :originalHtml into :submitter
      end
    end
  end
end

behavior TidePointBoot
  init
    call window.BadaRoUi.restoreTidesScrollPosition()
    call window.BadaRoUi.addRecentPointFromElement(me)
  end
end

behavior TideMonthJump
  on submit
    halt the event
    call window.BadaRoUi.navigateToTideMonthFromForm(me)
  end
end

behavior TideDayJump
  on submit
    halt the event
    call window.BadaRoUi.navigateToTideDayFromForm(me)
  end
end
