/**
 * Mixin for flush.
 * @mixin ApFlushMixin
 */

'use strict'

import React, {PropTypes as types} from 'react'
import assert from 'assert'

/** @lends ApFlushMixin */
let ApFlushMixin = {

  // --------------------
  // Custom
  // --------------------
  $apFlushMixed: true,

  /**
   * Flush message.
   * @param {string} msg - Message to show.
   */
  flush (msg) {
    if (!msg) {
      return
    }
    const s = this
    let [text, level] = msg.split(':').reverse()
    s.toast(text, level)
  },

  // --------------------
  // Lifecycle
  // --------------------

  componentWillMount () {
    const s = this
    assert.ok(s.$apToastMixed, 'ApToastMixin is required.')
  }
}

export default Object.freeze(ApFlushMixin)
