<?php // $Id$

/**
 * Implementation of hook_theme().
 */
function geo_data_theme_theme() {
  $path = drupal_get_path('module', 'geo_data') .'/theme';

  return array(
    'geo_data_formatter_default' => array(
      'arguments' => array('element' => NULL),
      'file' => 'geo_data.theme.inc',
      'path' => $path,
    ),
    'geo_data_formatter_key' => array(
      'arguments' => array('element' => NULL),
      'file' => 'geo_data.theme.inc',
      'path' => $path,
    ),
    'geo_data_select' => array(
      'arguments' => array('element' => NULL),
      'file' => 'geo_data.theme.inc',
      'path' => $path,
    ),
    'geo_data_admin_tables' => array(
      'arguments' => array('form' => NULL),
      'file' => 'geo_data.theme.inc',
      'path' => $path,
    ),
  );
}

/**
 * Default field theme function: return value field.
 */
function theme_geo_data_formatter_default($element) {
  return check_plain($element['#item']['label']);
}

/**
 * Default field theme function: return key field.
 */
function theme_geo_data_formatter_key($element) {
  return check_plain($element['#item']['value']);
}

/**
 * Theme function for the geo_data select element.
 */
function theme_geo_data_select($element) {
  return $element['#children'];
}

/**
 * Theme function for the geo_data table listing.
 */
function theme_geo_data_admin_tables($form) {
  $hdrs = array(
    t('Name'),
    t('Table'),
    t('Records'),
    '',
  );

  $rows = array();
  foreach (element_children($form['tables']) as $k => $table) {
    $row = array();
    $row[] = drupal_render($form['tables'][$k]['label']);
    $row[] = drupal_render($form['tables'][$k]['count']);
    $row[] = drupal_render($form['tables'][$k]);
    $rows[] = $row;
  }

  $output = theme('table', $hdrs, $rows);
  $output .= drupal_render($form);

  return $output;
}
