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

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

import Icon from "../icon";
import Popup from "../popup";
import Loading from "../loading";
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: {
        "position": "bottom",
        "round": _vm.round,
        "value": _vm.value,
        "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.togglePopup,
        "open": function open($event) {
          return _vm.onOpen('open');
        },
        "opened": function opened($event) {
          return _vm.onOpen('opened');
        },
        "close": function close($event) {
          return _vm.onOpen('close');
        },
        "closed": function closed($event) {
          return _vm.onOpen('closed');
        }
      }
    }, [_vm.title ? _c('div', {
      class: _vm.b('header')
    }, [_vm._v("\n    " + _vm._s(_vm.title) + "\n    "), _vm.closeable ? _c('Icon', {
      class: _vm.b('close'),
      attrs: {
        "name": _vm.closeIcon
      },
      on: {
        "click": _vm.onCancel
      }
    }) : _vm._e()], 1) : _vm._e(), _vm.$slots.description || _vm.description ? _c('div', {
      class: _vm.b('description')
    }, [_vm._t("description", [_vm._v("\n      " + _vm._s(_vm.description) + "\n    ")])], 2) : _vm._e(), _c('div', {
      class: _vm.b('content')
    }, [_vm._l(_vm.actions, function (item, index) {
      return _vm.actions ? _c('button', {
        key: index,
        class: [_vm.b('item', {
          disabled: item.disabled,
          loading: item.loading
        }), item.className],
        style: {
          color: item.color
        },
        attrs: {
          "type": "button"
        },
        on: {
          "click": function click($event) {
            return _vm.onClickOption($event, item, index);
          }
        }
      }, [item.loading ? _c('Loading', {
        class: _vm.b('loading-icon')
      }) : [_c('span', {
        class: _vm.b('name')
      }, [_vm._v(_vm._s(item.name))]), item.subname ? _c('div', {
        class: _vm.b('subname')
      }, [_vm._v("\n          " + _vm._s(item.subname) + "\n        ")]) : _vm._e()]], 2) : _vm._e();
    }), _vm._t("default")], 2), _vm.cancelText ? [_c('div', {
      class: _vm.b('gap')
    }), _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: {
    Icon: Icon,
    Popup: Popup,
    Loading: Loading
  },
  name: "action-sheet",
  props: _extends({}, popupMixin.props, {
    title: String,
    actions: Array,
    duration: [Number, String],
    cancelText: String,
    description: String,
    getContainer: [String, Function],
    closeOnPopstate: Boolean,
    closeOnClickAction: Boolean,
    round: {
      type: Boolean,
      default: true
    },
    closeable: {
      type: Boolean,
      default: true
    },
    closeIcon: {
      type: String,
      default: "close"
    },
    safeAreaInsetBottom: {
      type: Boolean,
      default: true
    },
    overlay: {
      type: Boolean,
      default: true
    },
    closeOnClickOverlay: {
      type: Boolean,
      default: true
    }
  }),
  methods: {
    togglePopup: function togglePopup(val) {
      this.$emit("input", val);
    },
    onOpen: function onOpen(name) {
      this.$emit(name);
    },
    onCancel: function onCancel() {
      this.$emit("input", false);
      this.$emit("cancel");
    },
    onClickOption: function onClickOption(event, item, index) {
      event.stopPropagation();
      var disabled = item.disabled,
          callback = item.callback,
          loading = item.loading;

      if (disabled || loading) {
        return;
      }

      if (callback) {
        callback(item);
      }

      this.$emit("select", item, index);

      if (this.closeOnClickAction) {
        this.$emit("input", false);
      }
    }
  }
});