import _extends from "@babel/runtime/helpers/esm/extends";
import create from "../utils/create"; // Mixins

import popupMixin from "../mixins/popup"; // Components

import Popup from "../popup";
var PRESET_ICONS = ["qq", "link", "weibo", "wechat", "poster", "qrcode", "weapp-qrcode"];
export default create({
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

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

    return _c('Popup', {
      class: _vm.b(),
      attrs: {
        "round": "",
        "value": _vm.value,
        "position": "bottom",
        "overlay": _vm.overlay,
        "duration": _vm.duration,
        "lazyRender": _vm.lazyRender,
        "lockScroll": _vm.lockScroll,
        "getContainer": _vm.getContainer,
        "closeOnPopstate": _vm.closeOnPopstate,
        "closeOnClickOverlay": _vm.closeOnClickOverlay,
        "safeAreaInsetBottom": _vm.safeAreaInsetBottom
      },
      on: {
        "input": _vm.toggle,
        "click-overlay": _vm.onClickOverlay
      }
    }, [_c('div', {
      class: _vm.b('header')
    }, [_vm._t("title", [_vm.title ? _c('h2', {
      class: _vm.b('title')
    }, [_vm._v("\n        " + _vm._s(_vm.title) + "\n      ")]) : _vm._e()]), _vm._t("description", [_vm.description ? _c('span', {
      class: _vm.b('description')
    }, [_vm._v("\n        " + _vm._s(_vm.description) + "\n      ")]) : _vm._e()])], 2), _vm._l(_vm.multiOptions, function (multiOption, index) {
      return _c('div', {
        key: "multiOption-" + index,
        class: _vm.b('options')
      }, _vm._l(multiOption, function (option, oIndex) {
        return _c('div', {
          key: "option-" + oIndex,
          class: [_vm.b('option'), option.className],
          attrs: {
            "role": "button",
            "tabindex": "0"
          },
          on: {
            "click": function click($event) {
              return _vm.onSelect(option, oIndex);
            }
          }
        }, [_c('img', {
          class: _vm.b('icon'),
          attrs: {
            "src": _vm.getIconURL(option.icon)
          }
        }), option.name ? _c('span', {
          class: _vm.b('name')
        }, [_vm._v(_vm._s(option.name))]) : _vm._e(), option.description ? _c('span', {
          class: _vm.b('option-description')
        }, [_vm._v("\n        " + _vm._s(option.description) + "\n      ")]) : _vm._e()]);
      }), 0);
    }), _vm.cancelText ? _c('button', {
      class: _vm.b('cancel'),
      attrs: {
        "type": "button"
      },
      on: {
        "click": _vm.onCancel
      }
    }, [_vm._v("\n    " + _vm._s(_vm.cancelText) + "\n  ")]) : _vm._e()], 2);
  },
  components: {
    Popup: Popup
  },
  name: "share-sheet",
  props: _extends({}, popupMixin.props, {
    duration: [Number, String],
    title: String,
    cancelText: {
      type: String,
      default: "取消"
    },
    description: String,
    getContainer: [String, Function],
    options: {
      type: Array,
      default: function _default() {
        return [];
      }
    },
    overlay: {
      type: Boolean,
      default: true
    },
    closeOnPopstate: {
      type: Boolean,
      default: true
    },
    safeAreaInsetBottom: {
      type: Boolean,
      default: true
    },
    closeOnClickOverlay: {
      type: Boolean,
      default: true
    }
  }),
  methods: {
    onCancel: function onCancel() {
      this.toggle(false);
      this.$emit("cancel");
    },
    onSelect: function onSelect(option, index) {
      this.$emit("select", option, index);
    },
    toggle: function toggle(val) {
      this.$emit("input", val);
    },
    getIconURL: function getIconURL(icon) {
      if (PRESET_ICONS.indexOf(icon) !== -1) {
        return "https://wuner.gitee.io/static-resources/varied-mobile/static/share-icon-" + icon + ".png";
      }

      return icon;
    },
    onClickOverlay: function onClickOverlay() {
      this.$emit("click-overlay");
    }
  },
  computed: {
    multiOptions: function multiOptions() {
      return Array.isArray(this.options[0]) ? this.options : [this.options];
    }
  }
});