<?php

/**
 * @file
 * Create and manage JBrowse instances.
 */

require_once 'includes/tripal_jbrowse_mgmt.api.inc';
require_once 'includes/tripal_jbrowse_mgmt.jobs.inc';
require_once 'includes/tripal_jbrowse_mgmt_commands.inc';

/**
 * Implements hook_menu().
 */
function tripal_jbrowse_mgmt_menu() {
  $items = [];

  // Admin forms.
  $items['admin/tripal/extension/tripal_jbrowse/management'] = [
    'title' => 'Tripal JBrowse Management',
    'description' => 'List JBrowse settings',
    'page callback' => 'tripal_jbrowse_mgmt_instances_page',
    'page arguments' => ['tripal_jbrowse_mgmt_configure_form'],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_list.page.inc',
    'type' => MENU_NORMAL_ITEM,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/instances'] = [
    'title' => 'List Instances',
    'description' => 'List JBrowse settings',
    'page callback' => 'tripal_jbrowse_mgmt_instances_page',
    'page arguments' => ['tripal_jbrowse_mgmt_configure_form'],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_list.page.inc',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/configure'] = [
    'title' => 'Settings',
    'description' => 'List and create JBrowse instances.',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_configure_form'],
    'access arguments' => ['configure tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_configure.form.inc',
    'type' => MENU_LOCAL_TASK,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/instances/add'] = [
    'title' => 'Add New Instance',
    'description' => 'List and create JBrowse instances.',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_add_form'],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_add.form.inc',
    'type' => MENU_LOCAL_ACTION,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/instances/%'] = [
    'title' => 'Manage Instance',
    'description' => 'View an instance and manage its tracks.',
    'page callback' => 'tripal_jbrowse_mgmt_instance_page',
    'page arguments' => [6],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_instance.page.inc',
    'type' => MENU_CALLBACK,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/instances/%/edit'] = [
    'title' => 'Edit Instance',
    'description' => 'Edit metadata for existing JBrowse instances.',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_add_form', 6],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_add.form.inc',
    'type' => MENU_LOCAL_ACTION,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/instances/%/delete'] = [
    'title' => 'Delete Instance',
    'description' => 'Confirm deleting an instance.',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_delete_instance_form', 6],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_delete_instance.form.inc',
    'type' => MENU_LOCAL_ACTION,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/instances/%/add_track'] = [
    'title' => 'Add New Track',
    'description' => 'Add new track to a jbrowse instance.',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_add_track_form', 6],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_tracks.form.inc',
    'type' => MENU_LOCAL_ACTION,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/tracks/%'] = [
    'title' => 'Edit Track',
    'description' => 'Edit tracks.',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_json_editor_form', 6],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_json_editor.form.inc',
    'type' => MENU_CALLBACK,
  ];

  $items['admin/tripal/extension/tripal_jbrowse/management/tracks/%/delete'] = [
    'title' => 'Delete Track',
    'page callback' => 'drupal_get_form',
    'page arguments' => ['tripal_jbrowse_mgmt_delete_track_form', 6],
    'access arguments' => ['administer tripal_jbrowse_mgmt'],
    'file' => 'includes/tripal_jbrowse_mgmt_tracks.form.inc',
    'type' => MENU_LOCAL_ACTION,
  ];

  return $items;
}

/**
 * Implements hook_permission().
 */
function tripal_jbrowse_mgmt_permission() {
  $items = [];

  $items['configure tripal_jbrowse_mgmt'] = [
    'title' => t('Configure Tripal JBrowse Management'),
  ];

  $items['administer tripal_jbrowse_mgmt'] = [
    'title' => t('Create, edit and delete JBrowse instances'),
  ];

  return $items;
}
