function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useState } from 'react';
import { PisellModal, PisellWalletPassCard, Iconfont } from '@pisell/materials';
import { Button } from 'antd';
import { getAvailableMaxAmount, voucherTime } from "../../utils";
var item1 = {
  id: 70652,
  shop_id: 9,
  customer_id: 9752,
  code: '785af187c3b74493',
  encoded: 'VC5742851573',
  status: 'partial_used',
  cover: '',
  tag: 'product_voucher',
  relation_type: 'product',
  product_id: 0,
  limit_status: 'enable',
  sales_status: 1,
  par_value: '10.00',
  used_par_value: '9.00',
  start_date: '2025-08-26',
  expire_date: '2026-02-26',
  end_time: '16:05',
  start_time: '16:05',
  created_at: '2025-08-26 16:05:14',
  product_name: '$$10-代金券',
  expire_time: '2026-02-26 16:05:14',
  total_order_behavior_count: 1,
  today_order_behavior_count: 1,
  week_order_behavior_count: 1,
  month_order_behavior_count: 1,
  balance_par_value: '1.00',
  available_max_amount: '1.00',
  available_max_par_value: '1.00',
  custom_expire_status: 0,
  wallet_pass_usage_unit: {
    price: 1,
    points: 1
  },
  custom_order_deduct_exhausted: 0,
  available_product_status: 1,
  custom_invalid_product: 0,
  custom_order_wallet_pass_behavior_info: {
    is_success: true
  },
  available_product_ids: [61031],
  available_product_type: 'product_all',
  available_num: 1,
  available_product_title: '',
  recommended_usage_par_value: '1.00',
  recommended_usage_amount: '1.00',
  unified_error_code: null,
  unified_available_status: 1,
  unified_messages: [],
  external_card: [],
  product: null,
  shop: {
    id: 9,
    name: '测试环境店铺09',
    default_url: 'https://'
  },
  extension_data: []
};
var item2 = {
  id: 70648,
  shop_id: 9,
  customer_id: 9752,
  code: '64abd351b42cf85c',
  encoded: 'VC6893431720',
  status: 'used',
  cover: '',
  tag: 'product_voucher',
  relation_type: 'product',
  product_id: 0,
  limit_status: 'enable',
  sales_status: 1,
  par_value: '10.00',
  used_par_value: '10.00',
  start_date: '2025-08-26',
  expire_date: '2026-02-26',
  end_time: '15:58',
  start_time: '15:58',
  created_at: '2025-08-26 15:58:54',
  product_name: '$$10-代金券',
  expire_time: '2026-02-26 15:58:54',
  total_order_behavior_count: 2,
  today_order_behavior_count: 2,
  week_order_behavior_count: 2,
  month_order_behavior_count: 2,
  balance_par_value: '0.00',
  available_max_amount: 0,
  available_max_par_value: '0.00',
  custom_expire_status: 0,
  wallet_pass_usage_unit: {
    price: 1,
    points: 1
  },
  custom_order_deduct_exhausted: 0,
  available_product_status: 1,
  custom_invalid_product: 0,
  custom_order_wallet_pass_behavior_info: {
    is_success: true
  },
  available_product_ids: [61031],
  available_product_type: 'product_all',
  available_num: 1,
  available_product_title: '',
  recommended_usage_par_value: '0.00',
  recommended_usage_amount: 0,
  unified_error_code: '500100',
  unified_available_status: 0,
  unified_messages: {
    title: '代金券已使用！',
    desc: '带有此编号的代金券已被使用。',
    alert: '已使用'
  },
  external_card: [],
  product: null,
  shop: {
    id: 9,
    name: '测试环境店铺09',
    default_url: 'https://'
  },
  extension_data: []
};
export var TestModule = function TestModule() {
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    show = _useState2[0],
    setShow = _useState2[1];
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    onClick: function onClick() {
      return setShow(true);
    }
  }, "show"), show && /*#__PURE__*/React.createElement(ConflictModal, {
    currentItem: item1,
    newItem: item2,
    onCancel: function onCancel() {
      return setShow(false);
    }
  }));
};
var ConflictModal = function ConflictModal(props) {
  var currentItem = props.currentItem,
    newItem = props.newItem,
    onSwitch = props.onSwitch,
    onCancel = props.onCancel,
    onSave = props.onSave;
  var handleSwitch = function handleSwitch() {
    onSwitch(newItem);
  };
  var handleSave = function handleSave() {
    onSave === null || onSave === void 0 || onSave(newItem);
  };
  var formatData = function formatData(item) {
    var _item$unified_message, _item$product;
    return {
      id: item.id,
      name: item.product_name,
      // storeName: item.shop?.name,
      balance: item.balance_par_value,
      redeem: getAvailableMaxAmount(item),
      showRedeem: true,
      showStoreName: false,
      showBalanceSymbol: item.tag !== 'point_card',
      // balanceTitle: item.tag !== 'point_card' ? "" : "",
      // redeemTitle: item.tag !== 'point_card' ? "" : "",
      showDetail: false,
      showQrCode: false,
      code: item.code,
      disabled: !item.unified_available_status,
      disabledReason: (_item$unified_message = item.unified_messages) === null || _item$unified_message === void 0 ? void 0 : _item$unified_message.title,
      cover: (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.cover,
      qrCode: item.code,
      validDate: voucherTime(item),
      originData: item
    };
  };
  var oldVoucher = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, "Previously Applied"), /*#__PURE__*/React.createElement(PisellWalletPassCard, _extends({}, formatData(currentItem), {
    type: "mini",
    style: {
      borderColor: '#7F56DA'
    }
  })));
  var newVoucher = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, "New Voucher"), /*#__PURE__*/React.createElement(PisellWalletPassCard, _extends({}, formatData(newItem), {
    type: "mini",
    style: {
      borderColor: '#7F56DA'
    }
  })));
  return /*#__PURE__*/React.createElement(PisellModal, {
    width: 680,
    open: true,
    platform: "pc",
    title: "Switch Voucher",
    onCancel: onCancel,
    headerDivider: false,
    footerDivider: false,
    footer: /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'space-between',
        width: '100%'
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        alignItems: 'center',
        gap: 16
      }
    }, /*#__PURE__*/React.createElement(Button, {
      style: {
        width: 150,
        height: 48,
        fontWeight: 600,
        color: '#7F56DA',
        border: '2px solid #7F56DA'
      },
      onClick: onCancel
    }, "Cancel"), /*#__PURE__*/React.createElement(Button, {
      style: {
        width: 150,
        height: 48,
        fontWeight: 600,
        color: '#7F56DA',
        border: '2px solid #7F56DA'
      },
      onClick: handleSave
    }, "Cancel & Save to Wallet")), /*#__PURE__*/React.createElement(Button, {
      type: "primary",
      style: {
        width: 240,
        height: 48
      },
      onClick: handleSwitch
    }, "Switch Voucher"))
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      flexWrap: 'nowrap',
      alignItems: 'center',
      justifyContent: 'space-between'
    }
  }, oldVoucher, /*#__PURE__*/React.createElement("div", {
    style: {
      border: '2px solid #7F56DA',
      width: 24,
      height: 24,
      borderRadius: 12,
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center'
    }
  }, /*#__PURE__*/React.createElement(Iconfont, {
    type: "pisell2-arrow-right",
    style: {
      transform: 'scale(1.3)',
      color: '#7F56DA'
    }
  })), newVoucher));
};
export default ConflictModal;