'use strict';Object.defineProperty(exports,'__esModule',{value:true});var normalizeComponent=require('./normalize-component-d9981c57.js');require('./es.array.includes-3990bfec.js');var index=require('./index-9dadef01.js'),DatePicker=require('vue2-datepicker'),fr=require('./fr-0bee2260.js'),BaseIcon=require('./BaseIcon-1ed3bf6e.js');require('./export-61511812.js'),require('./object-keys-12f2c5e5.js'),require('./es.array.concat-bb8715dc.js'),require('./array-species-create-c414c2ec.js'),require('./create-property-240c71a5.js'),require('./array-method-has-species-support-983ac207.js'),require('./es.array.join-88750c41.js'),require('./array-method-is-strict-99341ee3.js');function _interopDefaultLegacy(e){return e&&typeof e==='object'&&'default'in e?e:{'default':e}}var DatePicker__default=/*#__PURE__*/_interopDefaultLegacy(DatePicker);/**
 * Date Panel
 */

var script = {
  name: 'BaseDatePanel',
  components: {
    BaseIcon: BaseIcon["default"],
    DatePicker: DatePicker__default["default"]
  },
  directives: {
    ClickOutside: index.v
  },
  model: {
    prop: 'input',
    event: 'selected'
  },
  props: {
    /**
     * specify if icon should be displayed left or right <br>
     * valid values: 'left' | 'right'
     */
    iconPosition: {
      type: String,
      default: 'left',
      validator: function validator(val) {
        return ['left', 'right'].includes(val);
      }
    },

    /**
     * @model
     *
     * set input field from outside<br>
     * format: { date: 'yyyy-MM-dd' }
     */
    input: {
      type: Object,
      default: function _default() {
        return {};
      }
    },

    /**
     * show panel permanently
     */
    isInline: {
      type: Boolean,
      default: false
    },

    /**
     * label, required for usability purposes, handle
     * showing of label with property showLabel
     */
    label: {
      type: String,
      required: true
    },

    /**
     * set calendar language
     */
    language: {
      type: String,
      default: 'en'
    },

    /**
     * defines if input label should be visible
     */
    showLabel: {
      type: Boolean,
      default: true
    },

    /**
     * select type of calendar <br>
     * valid values: 'date' | 'week'
     */
    type: {
      type: String,
      default: 'date',
      validator: function validator(val) {
        return ['date', 'week'].includes(val);
      }
    },

    /**
     * label will be replace with selected date unless this is set false
     */
    showDateSelected: {
      type: Boolean,
      default: true
    }
  },
  data: function data() {
    return {
      inputInt: null,
      isOpen: false,

      /**
       * datepicker localisations
       *   using object fixes problem of missing localisation files in rollup-esm-build
       */
      lang: {
        de: fr.d,
        en: fr.e,
        fr: fr.f
      }
    };
  },
  computed: {
    labelInt: function labelInt() {
      if (!this.isInline && this.showDateSelected && this.inputInt) {
        return new Date(this.inputInt).toLocaleDateString(this.language);
      }

      return this.label;
    }
  },
  watch: {
    input: {
      handler: function handler(val) {
        // check if input string is different from inputInt
        if (val && this.inputInt && val.date !== this.inputInt) {
          this.inputInt = val.date;
        }
      },
      // to not need to do extra assignment in created()
      immediate: true
    },
    inputInt: {
      handler: function handler(val, before) {
        if (val && val !== before) {
          this.emitData(val);
          this.isOpen = false;
        }
      },
      deep: true
    }
  },
  methods: {
    /**
     * Define object to emit
     *
     * @param {string} date
     * @returns {object}
     */
    emitObject: function emitObject(date) {
      var obj = {
        date: date
      };

      if (this.type === 'week') {
        obj.week = this.$refs.datePanel.getWeek(new Date(date));
      }

      return obj;
    },

    /**
     * emit data function
     */
    emitData: function emitData(value) {
      /**
       * emit event when date or week is selected<br>
       * format: { date: 'yyyy-MM-dd' }
       *
       * @event selected
       * @param {Object} value - an object with the following properties:
       * @property {string} date - the date string in format 'YYYY-MM-DD'
       * @property {string} week - if type is 'week' also the week is emitted
       */
      this.$emit('selected', this.emitObject(value));
    }
  }
};/* script */
var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    directives: [{
      name: "click-outside",
      rawName: "v-click-outside",
      value: function value() {
        return _vm.isOpen = false;
      },
      expression: "() => isOpen = false"
    }],
    staticClass: "base-date-panel"
  }, [_vm._ssrNode("<div" + _vm._ssrClass(null, ['base-date-panel__label', {
    'base-date-panel__label--hover': !_vm.isInline
  }]) + " data-v-098daa39>", "</div>", [!_vm.isInline ? _c('base-icon', {
    class: ['base-date-panel__icon', {
      'base-date-panel__icon--active': _vm.isOpen
    }, {
      'base-date-panel__icon--right': _vm.iconPosition === 'right'
    }],
    attrs: {
      "name": "calendar-many"
    }
  }) : _vm._e(), _vm._ssrNode(" " + (_vm.showLabel || !_vm.isInline ? "<label data-v-098daa39>" + _vm._ssrEscape("\n      " + _vm._s(_vm.labelInt || _vm.label) + "\n    ") + "</label>" : "<!---->"))], 2), _vm._ssrNode(" "), _vm._ssrNode("<div data-v-098daa39>", "</div>", [_c('date-picker', {
    ref: "datePanel",
    attrs: {
      "append-to-body": false,
      "clearable": false,
      "editable": false,
      "inline": _vm.isInline,
      "input": _vm.input,
      "lang": _vm.lang[_vm.language],
      "type": _vm.type,
      "format": 'YYYY-MM-DD',
      "open": _vm.isOpen,
      "value-type": "format"
    },
    model: {
      value: _vm.inputInt,
      callback: function callback($$v) {
        _vm.inputInt = $$v;
      },
      expression: "inputInt"
    }
  })], 1)], 2);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-098daa39";
/* module identifier */

var __vue_module_identifier__ = "data-v-098daa39";
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent.n({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);

var BaseDatePanel = __vue_component__;var Plugin = {
  install: function install(Vue) {
    normalizeComponent.r(Vue, BaseDatePanel);
  }
};
normalizeComponent.u(Plugin);exports.BaseDatePanel=BaseDatePanel;exports["default"]=Plugin;