'use strict';

var StationBookingEditController = function($scope, $controller, $routeParams, StationBooking, formula,
  formulaAutoCompleteService, npdcAppConfig, chronopicService, fileFunnelService, NpolarLang, npolarApiConfig,
  NpolarApiSecurity, npolarCountryService, NpolarMessage) {
  'ngInject';

  // EditController -> NpolarEditController
  $controller('NpolarEditController', {
    $scope: $scope
  });

  // StationBooking -> npolarApiResource -> ngResource
  $scope.resource = StationBooking;

  let templates = [];

  let i18n = [{
      map: require('./en.json'),
      code: 'en'
    },
    {
      map: require('./no.json'),
      code: 'nb_NO',
    }];

  $scope.formula = formula.getInstance({
    schema: '//api.npolar.no/schema/station-booking',
    form: 'edit/formula.json',
    language: NpolarLang.getLang(),
    templates: npdcAppConfig.formula.templates.concat(templates),
    languages: npdcAppConfig.formula.languages.concat(i18n)
   });

  formulaAutoCompleteService.autocomplete({
    match: "@country",
    querySource: 'https://api.npolar.no/country',
    label: 'name',
    value: 'code'
  }, $scope.formula);

  let autocompleteFacets = ["people.first_name", "people.last_name", "people.organisation"];
  formulaAutoCompleteService.autocompleteFacets(autocompleteFacets, StationBooking, $scope.formula);


  chronopicService.defineOptions({ match: 'released', format: '{date}'});
  chronopicService.defineOptions({ match(field) {
    return field.path.match(/^#\/activity\/\d+\/.+/);
  }, format: '{date}'});

   $scope.edit();
};

module.exports = StationBookingEditController;

@@ -1335,16 +1335,18 @@
 la);%0A%0A%0A 
+//
  chronop
@@ -1411,16 +1411,18 @@
 e%7D'%7D);%0A 
+//
  chronop
@@ -1463,16 +1463,18 @@
 eld) %7B%0A 
+//
    retur
@@ -1519,16 +1519,18 @@
 /.+/);%0A 
+//
  %7D, form
@@ -1546,16 +1546,222 @@
 e%7D'%7D);%0A%0A
+//Set chronopic view format (this does not change the internal value, i.e. ISO string date)%0A chronopicService.defineOptions(%7B match(field) %7B%0A    return field.path.match(/_date$/);%0A %7D, format: '%7Bdate%7D'%7D);%0A%0A%0A
    $scop

date fix chronopic