text: /**
   * @license
   * Copyright 2018 Google Inc.
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
  
  import MDCFoundation from '@material/base/foundation';
  import MDCSelectHelperTextAdapter from './adapter';
  import {cssClasses, strings} from './constants';
  
  
  /**
   * @extends {MDCFoundation<!MDCSelectHelperTextAdapter>}
   * @final
   */
  class MDCSelectHelperTextFoundation extends MDCFoundation {
    /** @return enum {string} */
    static get cssClasses() {
      return cssClasses;
    }
  
    /** @return enum {string} */
    static get strings() {
      return strings;
    }
  
    /**
     * {@see MDCSelectHelperTextAdapter} for typing information on parameters and return
     * types.
     * @return {!MDCSelectHelperTextAdapter}
     */
    static get defaultAdapter() {
      return /** @type {!MDCSelectHelperTextAdapter} */ ({
        addClass: () => {},
        removeClass: () => {},
        hasClass: () => {},
        setAttr: () => {},
        removeAttr: () => {},
        setContent: () => {},
      });
    }
  
    /**
     * @param {!MDCSelectHelperTextAdapter} adapter
     */
    constructor(adapter) {
      super(Object.assign(MDCSelectHelperTextFoundation.defaultAdapter, adapter));
    }
  
    /**
     * Sets the content of the helper text field.
     * @param {string} content
     */
    setContent(content) {
      this.adapter_.setContent(content);
    }
  
    /** @param {boolean} isPersistent Sets the persistency of the helper text. */
    setPersistent(isPersistent) {
      if (isPersistent) {
        this.adapter_.addClass(cssClasses.HELPER_TEXT_PERSISTENT);
      } else {
        this.adapter_.removeClass(cssClasses.HELPER_TEXT_PERSISTENT);
      }
    }
  
    /**
     * @param {boolean} isValidation True to make the helper text act as an
     *   error validation message.
     */
    setValidation(isValidation) {
      if (isValidation) {
        this.adapter_.addClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
      } else {
        this.adapter_.removeClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
      }
    }
  
    /** Makes the helper text visible to the screen reader. */
    showToScreenReader() {
      this.adapter_.removeAttr(strings.ARIA_HIDDEN);
    }
  
    /**
     * Sets the validity of the helper text based on the select validity.
     * @param {boolean} selectIsValid
     */
    setValidity(selectIsValid) {
      const helperTextIsPersistent = this.adapter_.hasClass(cssClasses.HELPER_TEXT_PERSISTENT);
      const helperTextIsValidationMsg = this.adapter_.hasClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
      const validationMsgNeedsDisplay = helperTextIsValidationMsg && !selectIsValid;
  
      if (validationMsgNeedsDisplay) {
        this.adapter_.setAttr(strings.ROLE, 'alert');
      } else {
        this.adapter_.removeAttr(strings.ROLE);
      }
  
      if (!helperTextIsPersistent && !validationMsgNeedsDisplay) {
        this.hide_();
      }
    }
  
    /**
     * Hides the help text from screen readers.
     * @private
     */
    hide_() {
      this.adapter_.setAttr(strings.ARIA_HIDDEN, 'true');
    }
  }
  
  export default MDCSelectHelperTextFoundation;
  