"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _one = require("remax/one");

var _classnames = _interopRequireDefault(require("classnames"));

var _popup = _interopRequireDefault(require("../popup"));

var _icon = _interopRequireDefault(require("../icon"));

var _common = require("../common");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var prefixCls = (0, _common.getPrefixCls)('action-sheet');

var ActionSheet = function ActionSheet(props) {
  var open = props.open,
      title = props.title,
      actions = props.actions,
      _props$cancelText = props.cancelText,
      cancelText = _props$cancelText === void 0 ? 'Cancel' : _props$cancelText,
      cover = props.cover,
      _props$maskClosable = props.maskClosable,
      maskClosable = _props$maskClosable === void 0 ? true : _props$maskClosable,
      onCancel = props.onCancel,
      onChange = props.onChange;

  var handleCancel = function handleCancel(e) {
    onCancel === null || onCancel === void 0 ? void 0 : onCancel(e);
  };

  var handleChange = function handleChange(action, grid, e) {
    onChange === null || onChange === void 0 ? void 0 : onChange(action, grid, e);
  };

  var handleCloseMask = function handleCloseMask() {
    maskClosable && (onCancel === null || onCancel === void 0 ? void 0 : onCancel());
  };

  var renderAction = function renderAction(action) {
    return /*#__PURE__*/_react.default.createElement(_one.View, {
      key: action.value,
      className: (0, _classnames.default)("".concat(prefixCls, "-action"), _defineProperty({}, "".concat(prefixCls, "-action-destructive"), action.type === 'destructive')),
      onTap: function onTap(e) {
        return handleChange(action, undefined, e);
      }
    }, action.text);
  };

  var renderGrid = function renderGrid(action) {
    var _a;

    return /*#__PURE__*/_react.default.createElement(_one.View, {
      key: action.value,
      className: (0, _classnames.default)("".concat(prefixCls, "-grid"), _defineProperty({}, "".concat(prefixCls, "-action-destructive"), action.type === 'destructive'))
    }, /*#__PURE__*/_react.default.createElement(_one.View, {
      className: "".concat(prefixCls, "-grid-wrapper")
    }, (_a = action.text) === null || _a === void 0 ? void 0 : _a.map(function (item) {
      return /*#__PURE__*/_react.default.createElement(_one.View, {
        key: item.value,
        className: "".concat(prefixCls, "-grid-item"),
        onTap: function onTap(e) {
          return handleChange(item, action, e);
        }
      }, /*#__PURE__*/_react.default.createElement(_one.View, {
        className: "".concat(prefixCls, "-grid-item-icon")
      }, item.icon ? /*#__PURE__*/_react.default.createElement(_icon.default, {
        type: item.icon,
        size: "48px",
        color: "rgba(0, 0, 0, 0.8)"
      }) : item.name), /*#__PURE__*/_react.default.createElement(_one.View, {
        className: "".concat(prefixCls, "-grid-item-name")
      }, item.name));
    })));
  };

  return /*#__PURE__*/_react.default.createElement(_one.View, {
    className: prefixCls
  }, /*#__PURE__*/_react.default.createElement(_popup.default, {
    transparent: true,
    position: "bottom",
    overlay: open,
    onClose: handleCloseMask
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)("".concat(prefixCls, "-container"), _defineProperty({}, "".concat(prefixCls, "-cover"), cover))
  }, /*#__PURE__*/_react.default.createElement(_one.View, {
    className: "".concat(prefixCls, "-menu")
  }, title ? /*#__PURE__*/_react.default.createElement(_one.View, {
    className: (0, _classnames.default)("".concat(prefixCls, "-action"), _defineProperty({}, "".concat(prefixCls, "-title"), true))
  }, title) : null, actions === null || actions === void 0 ? void 0 : actions.map(function (action) {
    return action.mode === 'grid' ? renderGrid(action) : renderAction(action);
  })), /*#__PURE__*/_react.default.createElement(_one.View, {
    className: "".concat(prefixCls, "-cancel"),
    onTap: handleCancel
  }, cancelText))));
};

var _default = ActionSheet;
exports.default = _default;