/*! bxs-vue-ui v3.3.0 */
import '../utils/entry-virtual.js';
import { C as create, _ as __vue_normalize__ } from '../utils/normalize-component.js';
import '../utils/object-create.js';
import '../utils/html.js';
import '../utils/es.number.constructor.js';
import '../utils/array-iteration.js';
import '../utils/sloppy-array-method.js';
import '../utils/for-each.js';
import '../utils/map.js';
import '../utils/index-of.js';
import '../utils/string-trim.js';
import '../utils/parse-int.js';
import '../utils/filter.js';
import { _ as _extends } from '../utils/extends.js';
import 'better-scroll';
import '../utils/index.js';
import '../utils/some.js';
import Vue from 'vue';
import '../utils/env.js';
import '../safe-area-patch/index.js';
import '../icon/index.js';
import bottomSheets from '../bottom-sheets/index.js';
import '../utils/splice.js';
import { P as PickerView } from '../utils/picker.js';
import '../utils/stringify.js';

var _components;
var script = create({
  name: 'pop-picker',
  props: {},
  data: function data() {
    return {
      isShow: false,
      title: '',
      showToolbar: true,
      pickerData: [],
      defaultValue: '',
      value: '',
      findValue: '',
      index: '',
      indexs: '',
      pickerObj: {},
      valueKey: 'text',
      isChange: false
    };
  },
  computed: {},
  methods: {
    cancel: function cancel() {
      this.isShow = false;
      this.$emit('cancel', false);
    },
    confirm: function confirm(pickerObj, value, index, indexs) {
      this.isShow = false;
      this.pickerObj = pickerObj;
      this.findValue = value;
      this.index = index;
      this.indexs = indexs;
      this.$emit('confirm', this.pickerObj, this.findValue, this.index, this.indexs);
    },
    sure: function sure() {
      if (!this.isChange) {
        this.$refs.bxsPicker.confirm();
        return;
      }

      this.isShow = false;
      this.$emit('confirm', this.pickerObj, this.findValue, this.index, this.indexs);
    },
    change: function change(pickerObj, value, index, indexs) {
      this.isChange = true;
      this.pickerObj = pickerObj;
      this.findValue = value;
      this.index = index;
      this.indexs = indexs;
      this.$emit('change', pickerObj, value, index, indexs);
    }
  },
  watch: {
    value: function value(n) {
      this.$emit('input', n);
    }
  },
  components: (_components = {}, _components[PickerView.name] = PickerView, _components[bottomSheets.name] = bottomSheets, _components)
});

/* 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('bxs-bottom-sheets', {
    attrs: {
      "prevent-scroll-through": true
    },
    on: {
      "after-leave": function afterLeave($event) {
        _vm.$emit('after-leave');
      }
    },
    model: {
      value: _vm.isShow,
      callback: function callback($$v) {
        _vm.isShow = $$v;
      },
      expression: "isShow"
    }
  }, [_c('div', {
    staticClass: "bx-picker-sheets-header",
    attrs: {
      "slot": "header"
    },
    slot: "header"
  }, [_vm.showToolbar ? _c('div', {
    staticClass: "bx-picker-header bx-hairline--bottom"
  }, [_c('p', {
    staticClass: "bx-picker-cancel",
    on: {
      "click": function click($event) {
        _vm.cancel();
      }
    }
  }, [_vm._v("\n        取消\n      ")]), _c('p', {
    staticClass: "bx-picker-title"
  }, [_vm._v("\n        " + _vm._s(_vm.title) + "\n      ")]), _c('p', {
    staticClass: "bx-picker-sure",
    on: {
      "click": function click($event) {
        _vm.sure();
      }
    }
  }, [_vm._v("\n        确定\n      ")])]) : _vm._e()]), _c('bxs-picker', {
    ref: "bxsPicker",
    attrs: {
      "picker-data": _vm.pickerData,
      "value": _vm.defaultValue,
      "value-key": _vm.valueKey
    },
    on: {
      "change": _vm.change,
      "confirm": _vm.confirm
    }
  })], 1);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

var PopPickerView = __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

var PickerConstructor = Vue.extend(PopPickerView);
var instance;

var getAnInstance = function getAnInstance() {
  return new PickerConstructor({
    el: document.createElement('div')
  });
};

function Picker(options) {
  instance = getAnInstance();

  _extends(instance, _extends({}, options));

  instance.$on('confirm', function (picker, value, index, indexs) {
    if (typeof options.callback === 'function') {
      options.callback({
        type: 'confirm',
        picker: picker,
        value: value,
        index: index,
        indexs: indexs
      });
    }

    instance.$on('after-leave', function () {
      return instance.$destroy();
    });
  });
  instance.$on('change', function (picker, value, index) {
    if (typeof options.callback === 'function') {
      options.callback({
        type: 'change',
        picker: picker,
        value: value,
        index: index
      });
    }
  });
  instance.$on('input', function (value) {
    instance.value = value;
  });

  if (typeof options === 'string') {
    instance.title = options;
  }

  document.body.appendChild(instance.$el);
  instance.isShow = false;
  Vue.nextTick(function () {
    instance.isShow = true;
    instance.showToolbar = true;

    if (options.pickerData) {
      instance.index = options.index ? options.index : 0;
      instance.defaultValue = options.defaultValue ? options.defaultValue : [options.pickerData[instance.index]];
    }
  });
}

Picker.install = function (vueGlobal) {
  var vueGlobalObj = vueGlobal;
  vueGlobalObj.use(PickerView);
  vueGlobalObj.use(PopPickerView);
  vueGlobalObj.prototype.$picker = Picker;
};

export default Picker;
