"use strict"

angular.module('avalanche3mobile.missionData', [])
.service('missionData', [ '$rootScope', '$http', function($rootScope, $http) {
  var data = [];
  var data_loaded = false;
  var currentMission = "";

  var currentMissions = [
    {
      title: "Test Mission",
      slug: "test-mission",
      cover: "http://localhost:5000/uploads/cover_img/1/thumb_0_78a0f_bf4b86b6_orig.jpg",
      status: 'Completed',
      description: "Test the Avalanche Network system",
      activities: [
        {
          id: "0",
          user_id: "1",
          action: "create",
          trackable_type: "Mission",
          trackable_id: "0",
          template: "templates/activities/mission_create.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            user: { user_id: 1, username: "jamesperet"}
          }
        },
        {
          id: "1",
          user_id: "1",
          action: "update",
          trackable_type: "Mission",
          trackable_id: "0",
          template: "templates/activities/mission_update.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            user: { user_id: 1, username: "jamesperet"}
          }
        },
        {

          id: "2",
          user_id: "1",
          action: "create",
          trackable_type: "MissionAgent",
          trackable_id: "0",
          template: "templates/activities/mission_agent_create.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            mission_agent: {role: "Beta Tester"},
            user: { user_id: 1, username: "jamesperet"}
          }
        },
        {
          id: "3",
          user_id: "1",
          action: "create",
          trackable_type: "Message",
          trackable_id: "0",
          template: "templates/activities/message.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            message: "<p>Testing messsage system 1 2 3</p>",
            user: { user_id: 1, username: "jamesperet", avatar: "http://localhost:5000/uploads/avatar/1/Glitchatron_1418584006282.png"}
          }
        },
        {
          id: "4",
          user_id: "1",
          action: "create",
          trackable_type: "Message",
          trackable_id: "0",
          template: "templates/activities/message.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            message: "<p>Parece que esta funcionando!</p><p>Ainda tem bastante coisa para fazer, mas no final vai ficar muito legal esse layout novo para mobile.</p>",
            user: { user_id: 2, username: "monty_cantsin", avatar: "http://localhost:5000/uploads/avatar/2/Istvan-Kantor-4252edited1-383x370.jpg"}
          }
        },
        {
          id: "5",
          user_id: "1",
          action: "create",
          trackable_type: "Task",
          trackable_id: "0",
          template: "templates/activities/task_create.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            task: { title: "Avl3 Layout", status: "incomplete"},
            user: { user_id: 2, username: "monty_cantsin", avatar: "http://localhost:5000/uploads/avatar/2/Istvan-Kantor-4252edited1-383x370.jpg"}
          }
        },
        {
          id: "6",
          user_id: "1",
          action: "mark_as_done",
          trackable_type: "Task",
          trackable_id: "0",
          template: "templates/activities/task_done.html",
          data: {
            mission: {title: "Test Mission", slug: "test-mission"  },
            task: { title: "Avalanche Agent App Front end development", status: "done"},
            user: { user_id: 1, username: "jamesperet", avatar: "http://localhost:5000/uploads/avatar/1/Glitchatron_1418584006282.png"}
          }
        }
      ]
    },
    {
      title: "Launch Party",
      slug: "launch-party",
      cover: "http://localhost:5000/uploads/cover_img/13/thumb_unt_passport_00.jpg",
      status: 'Planning',
      description: "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>"
    },
    {
      title: "Another realy long test mission",
      slug: "another-realy-long-test-mission",
      cover: "http://localhost:5000/uploads/cover_img/20/feature_tumblr_m7qyjg3cwT1rzupqxo1_500.jpeg",
      status: 'Failed',
      description: "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.</p>"
    },
    {
      title: "Avalanche Mobile App",
      slug: "avalanche-mobile-app",
      cover: "http://localhost:5000/uploads/cover_img/5/feature_Avalanche_Agent_Android_App_Mission_Cover.jpg",
      status: 'Launched',
      description: "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.   Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>"
    },
  ]

  // $http({
  //   method: 'GET',
  //   url: 'scripts/data.json'
  // }).success(function(json_data) {
  //   data = json_data;
  //   data_loaded = true;
  //   $rootScope.$broadcast('data:loaded', data);
  //   console.log('> Loaded data.json');
  // });

  this.get = function() {
    return currentMissions;
  }

  this.findMission = function(url) {
    for (var i = 0; i < currentMissions.length; i++) {
      if(currentMissions[i].slug == url) {
        currentMission = currentMissions[i];
        return currentMissions[i];
      }
    }
    return "";
  }

  this.getCurrentMission = function() {
    return currentMission;
  }

}]);
