import ApplicationController from './application_controller'

/* This is the custom StimulusReflex controller for the <%= class_name %> Reflex.

* Learn more at: https://docs.stimulusreflex.com
*/

export default class extends ApplicationController {

/*
 * Regular Stimulus lifecycle methods
 * Learn more at: https://stimulusjs.org/reference/lifecycle-callbacks
 *
 * If you intend to use this controller as a regular stimulus controller as well,
 * make sure any Stimulus lifecycle methods overridden in ApplicationController call super.
 *
 * Important:
 * By default, StimulusReflex overrides the -connect- method so make sure you
 * call super if you intend to do anything else when this controller connects.
*/

connect () {
  super.connect()
  // add your code here, if applicable
}

/* Reflex specific lifecycle methods.
 *
 * For every method defined in your Reflex class, a matching set of lifecycle methods become available
 * in this javascript controller. These are optional, so feel free to delete these stubs if you don't
 * need them.
 *
 * Important:
 * Make sure to add data-controller="<%= class_name.underscore.dasherize %>" to your markup alongside
 * data-reflex="<%= class_name %>#dance" for the lifecycle methods to fire properly.
 *
 * Example:
 *
 *   <a href="#" data-reflex="click-><%= class_name %>#dance" data-controller="<%= class_name.underscore.dasherize %>">Dance!</a>
 *
 * Arguments:
 *
 *   element - the element that triggered the reflex
 *             may be different than the Stimulus controller's this.element
 *
 *   reflex - the name of the reflex e.g. "<%= class_name %>#dance"
 *
 *   error/noop - the error message (for reflexError), otherwise null
 *
 *   reflexId - a UUID4 or developer-provided unique identifier for each Reflex
 */

<% if actions.empty? -%>

// Assuming you create a "<%= class_name %>#dance" action in your Reflex class
// you'll be able to use the following lifecycle methods:

// beforeDance(element, reflex, noop, reflexId) {
//  element.innerText = 'Putting dance shoes on...'
// }

// danceSuccess(element, reflex, noop, reflexId) {
//   element.innerText = '\nDanced like no one was watching! Was someone watching?'
// }

// danceError(element, reflex, error, reflexId) {
//   console.error('danceError', error);
//   element.innerText = "\nCouldn\'t dance!"
// }

// afterDance(element, reflex, noop, reflexId) {
//   element.innerText = '\nWhatever that was, it\'s over now.'
// }

// finalizeDance(element, reflex, noop, reflexId) {
//   element.innerText = '\nNow, the cleanup can begin!'
// }

<% end -%> <% actions.each do |action| -%>

// <%= "before_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
//  console.log("before <%= action %>", element, reflex, reflexId)
// }

// <%= "#{action}_success".camelize(:lower) %>(element, reflex, noop, reflexId) {
//   console.log("<%= action %> success", element, reflex, reflexId)
// }

// <%= "#{action}_error".camelize(:lower) %>(element, reflex, error, reflexId) {
//   console.error("<%= action %> error", element, reflex, error, reflexId)
// }

// <%= "#{action}_halted".camelize(:lower) %>(element, reflex, noop, reflexId) {
//   console.warn("<%= action %> halted", element, reflex, reflexId)
// }

// <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
//   console.log("after <%= action %>", element, reflex, reflexId)
// }

// <%= "finalize_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
//   console.log("finalize <%= action %>", element, reflex, reflexId)
// }

<%= ā€œnā€ unless action == actions.last -%> <% end -%> }