import template from './ws-date-picker.tmpl.html';
import WsDatePickerController from './ws-date-picker.controller';

/**
 * This is a date picker that wraps a 3rd party date picker. It helps set default
 * min and max dates, and converts the underlying date value for WS API's servers.
 *
 * If the default date is set to a disabled date, placeholderText will be used.
 *
 * This may or may not be generic enough to extract to WS-Directives, given that
 * there's a certain ngModel format for the date.
 *
 * How to use:
 * CSS
 * Import "_ws-date-picker.scss" into your project for WS - theme
 *
 * Requirements:
 * Angular 1.3+
 * https://github.com/720kb/angular-datepicker/ 2.1.23
 * https://github.com/urish/angular-moment ^2.1.6
 */
const WsDatePickerComponent = {
  template,
  controller: WsDatePickerController,
  require: {
    ctrlNgModel: '?ngModel',
  },
  bindings: {
    // The binding for the ngModel
    ngModel: '<',
    /* Format the date is displayed in to the user
     Possible data formats: https://docs.angularjs.org/api/ng/filter/date
     Must be passed as a properly quoted string
     Default is 'MMM d, yyyy' */
    format: '<',
    minDate: '@', // Is inclusive
    maxDate: '@', // Is inclusive
    // If minDate is not set, minYear will be used. Is inclusive.
    minYear: '@',
    // If maxDate is not set, maxYear will be used. Is inclusive.
    maxYear: '@',
    /* Sets the selected date to minDate + 1 day unless this is set.
     Uses base JavaScript toString() formatting so be wary of JavaScript dateString features */
    defaultDate: '<',
    /* Array of date strings using the 'YYYY/MM/DD' format.
     E.g. disabled-dates="['2017/01/05', '2017/01/20']" */
    disabledDates: '<',
    // Boolean value. Defaults to false
    disableWeekends: '<',
    // Disables the next N days from the CURRENT date. Does not use the default date.
    disableNextNDays: '<',
    // Disables the next N business days from the CURRENT date. Does not use the default date.
    disableNextNBusinessDays: '<',
    // First day of the week that is displayed to the user. Defaults to 'sunday'
    firstDayOfWeek: '@',
    // Test displayed if there is no selected date
    placeholderText: '@',
    // Name for form validation
    name: '@',
    // Whether to allow the input to be blank
    allowBlank: '<',
    // Whether to allow the input to be editable
    editable: '<',
    // Either 'size-md' or 'size-sm'. Default is 'size-sm'
    sizeCssClass: '@',
  },
};

export default WsDatePickerComponent;
