/**
 * Manager Class Application
 *
 * @package    Portal
 * @category   Application
 * @author     Everett Myers <Everett@AllSportsEquine.com>
 * @copyright  2013-2021 All Sports Equine, All Rights Reserved
 * @link       https://www.AllSportsEquine.com/portal/AReact/Application.html
 * @version    1.0.0 2021-03-04
 */

// -------------------------------------------------------------------------------------------------

/**
 * Manager Application
 *
 * This is the base or root application for the portal.
 *
 * Paths this class handles:
 * Class - /manager/shows/{SHOW-ID}/classes/{class-id}.html (NOTE: this is a hand off to the manager class app)
 */
class ManagerClassApp extends App {

  /**
   * Constructor
   *
   * The constructor for a React component is called before it is mounted. When
   * implementing the constructor for a React.Component subclass, you should
   * call super(props) before any other statement. Otherwise, this.props will be
   * undefined in the constructor, which can lead to bugs. The initialized state
   * will be set to FALSE with initializing being added to waiting state to
   * ensure initialize() will be called after componentDidMount().
   *
   * @param object props
   *
   * @return void
   */
  constructor(props) {

    // =========================================================================
    // SET THIS STATE
    // =========================================================================
    const stateUpdater = {
      waiting: ['initializing','account-loading']
    }

    // =========================================================================
    // PARENT
    // =========================================================================
    super(props)

    // =========================================================================
    // PARENT APP LINKS (note DO NOT link states here)
    // =========================================================================
    this.MainApp    = props.parentApp.MainApp
    this.ManagerApp = props.parentApp.ManagerApp
    this.ManagerShowApp = props.parentApp

    // =========================================================================
    // SET THIS STATE
    // =========================================================================
    Object.assign(this.state, {

    })

  }

  // ---------------------------------------------------------------------------------------------

  /**
   * Render
   *
   * The render() method is used to create new elements for the DOM. This is
   * normally where the main <Switch> and <Route> elements are placed for this
   * application.
   *
   * @return <element>
   */
  render() {

    // =========================================================================
    // DEBUG
    // =========================================================================
    if (appDebug.includes('lifecycle')) {
      console.log('ManagerClassApp.render()')
    }

    // =========================================================================
    // RENDER REDIRECT/LOADING
    // =========================================================================
    const parentRender = super.render()
    if (parentRender != null) {
      return parentRender
    }

    // =========================================================================
    // BASE URIs
    // =========================================================================
      const base_url = '/manager/'+CONFIG.show.uri+'/:show_id/classes/:class_id'

    // =========================================================================
    // RENDER
    // =========================================================================
    return (
      <Switch>
        <Route path={base_url+'/edit_qualifications.html'} render={ p => this.renderEditQualifications(p)} />

        <Route path="*" render={ p => this.renderNotFound(p)} />
      </Switch>
    )

  }

  renderEditQualifications() {

    // -------------------------------------------------------------------------
    // GET PARENT STATES ITEMS
    // -------------------------------------------------------------------------
    const showObject = this.ManagerApp.state.showObject
    const classObject = this.ManagerApp.state.classObject
    const return_url = `/manager/${CONFIG.show.uri}/${showObject.show_id}/classes.html`

    // -------------------------------------------------------------------------
    // NOT LOADED YET
    // -------------------------------------------------------------------------
    if (showObject.classes.length == 0) {
      return this.renderLoading(null, 'ManagerShowApp.showObject')
    }

    // -------------------------------------------------------------------------
    // RENDER
    // -------------------------------------------------------------------------
    return (
      <div className="event-list results-list">
        <div className="event-header page-header">
          <h1>{showObject.name}</h1>
          {showObject.dateRangeFormat('html_wrap')}
          <button className="action" onClick={ () => this.transitionTo(return_url)}>Back</button>
        </div>
        <table className="default">
          <thead>
            <tr>
              <th>ID</th>
              <th>Class</th>
              <th>Calculate</th>
              <th>Qualifications</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
      </div>
    )
    
  }

}

// EOF /////////////////////////////////////////////////////////////////////////////////////////////
