"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _reactNativeGestureHandler = require("react-native-gesture-handler");
var _Swipeable = _interopRequireDefault(require("react-native-gesture-handler/Swipeable"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
class ChatSwipeableRow extends _react.Component {
  constructor() {
    super(...arguments);
    _defineProperty(this, "renderLeftActions", (_progress, dragX) => {
      const trans = dragX.interpolate({
        inputRange: [0, 50, 100, 101],
        outputRange: [-20, 0, 0, 1],
        extrapolate: 'clamp'
      });
      return /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.RectButton, {
        style: styles.leftAction,
        onPress: this.close
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.Text, {
        style: [styles.actionText, {
          transform: [{
            translateX: trans
          }]
        }]
      }, "Archive"));
    });
    _defineProperty(this, "renderRightAction", (text, icon, color, x, progress, onPress) => {
      const trans = progress.interpolate({
        inputRange: [0, 1],
        outputRange: [x, 0]
      });
      const pressHandler = () => {
        if (onPress) onPress();
        this.close();
      };
      return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
        style: {
          flex: 1,
          transform: [{
            translateX: trans
          }]
        }
      }, /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.RectButton, {
        style: [styles.rightAction, {
          backgroundColor: color
        }],
        onPress: pressHandler
      }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
        style: {
          width: 20,
          height: 20,
          resizeMode: 'contain'
        },
        source: icon
      }), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
        style: styles.actionText
      }, text)));
    });
    _defineProperty(this, "renderRightActions", (progress, _dragAnimatedValue) => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        width: 192,
        flexDirection: _reactNative.I18nManager.isRTL ? 'row-reverse' : 'row'
      }
    }, this.renderRightAction('Bỏ ghim', require('../assets/ic_unpin.png'), '#3B7CEC', 198, progress, this.props.onPress1), this.renderRightAction('Xoá', require('../assets/ic_trash.png'), '#EE0033', 66, progress, this.props.onPress3)));
    _defineProperty(this, "swipeableRow", void 0);
    _defineProperty(this, "updateRef", ref => {
      this.swipeableRow = ref;
    });
    _defineProperty(this, "close", () => {
      var _this$swipeableRow;
      (_this$swipeableRow = this.swipeableRow) === null || _this$swipeableRow === void 0 ? void 0 : _this$swipeableRow.close();
    });
  }
  render() {
    const {
      children
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_Swipeable.default, {
      ref: this.updateRef,
      friction: 2,
      enableTrackpadTwoFingerGesture: true,
      leftThreshold: 30,
      rightThreshold: 40
      // renderLeftActions={this.renderLeftActions}
      ,
      renderRightActions: this.renderRightActions,
      onSwipeableOpen: direction => {
        (0, _utils.Log)(`Opening swipeable from the ${direction}`);
      },
      onSwipeableClose: direction => {
        (0, _utils.Log)(`Closing swipeable to the ${direction}`);
      }
    }, children);
  }
}
exports.default = ChatSwipeableRow;
const styles = _reactNative.StyleSheet.create({
  leftAction: {
    flex: 1,
    backgroundColor: '#497AFC',
    justifyContent: 'center'
  },
  actionText: {
    color: 'white',
    fontSize: 13,
    backgroundColor: 'transparent',
    textAlign: 'center',
    paddingTop: 4
  },
  rightAction: {
    alignItems: 'center',
    flex: 1,
    justifyContent: 'center'
  }
});
//# sourceMappingURL=ChatSwipeableRow.js.map