<?php

/**
 * @file
 * Install, update, and uninstall functions for the chartjs module.
 */

/**
 * Implements hook_requirements().
 */
function chartjs_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
    $libraries = array(
      'chartjs' => 'Chart.js',
    );
    foreach ($libraries as $lib => $label) {
      $requirements['chartjs_' . $lib] = array(
        'title' => t('Chart.js: @library library', array('@library' => $label)),
        'value' => t('The @library library is not present', array('@library' => $label)),
        'severity' => REQUIREMENT_ERROR,
      );
      if (function_exists('libraries_detect')) {
        if (($library = libraries_detect($lib)) && !empty($library['installed'])) {
          $requirements['chartjs_' . $lib]['value'] = t('@version (@variant)', array(
            '@version' => $library['version'],
            '@variant' => TRUE
          ));
          $requirements['chartjs_' . $lib]['severity'] = REQUIREMENT_OK;
        }
        elseif (!empty($library['error'])) {
          $requirements['chartjs_' . $lib]['description'] = $library['error message'];
        }
      }
    }
  }

  return $requirements;
}