import React from 'react';
import { Button, Dropdown } from 'antd';
import { ClockCircleOutlined, LinkOutlined } from '@ant-design/icons';

// @ts-ignore - @pisell/utils types not available
import { locales } from '@pisell/utils';
import { Icon } from '@pisell/materials';
import "./index.less";
import { getLocale } from "../../../../utils/locales";
import localeTexts from "./locales";
import useToast from "../../../../hooks/useToast";
function AdditionalModule(_ref) {
  var orderInfo = _ref.orderInfo,
    customAmount = _ref.customAmount,
    handleButtonClick = _ref.handleButtonClick,
    _ref$hasOrderNote = _ref.hasOrderNote,
    hasOrderNote = _ref$hasOrderNote === void 0 ? false : _ref$hasOrderNote,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$showCashPayment = _ref.showCashPayment,
    showCashPayment = _ref$showCashPayment === void 0 ? false : _ref$showCashPayment,
    _ref$isFullWidth = _ref.isFullWidth,
    isFullWidth = _ref$isFullWidth === void 0 ? false : _ref$isFullWidth,
    _ref$showMore = _ref.showMore,
    showMore = _ref$showMore === void 0 ? true : _ref$showMore;
  // 初始化国际化
  locales.init(localeTexts, getLocale());

  // 定义更多按钮的菜单项
  var moreMenuItems = [{
    key: 'send-link',
    label: locales.getText('pisell2.text.send-link'),
    icon: /*#__PURE__*/React.createElement(LinkOutlined, null)
  }, {
    key: 'print-receipt',
    label: locales.getText('pisell2.text.print-receipt'),
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-printer"
    })
  }];
  var Toast = useToast();
  return /*#__PURE__*/React.createElement("div", {
    className: "additional-module"
  }, showCashPayment && /*#__PURE__*/React.createElement("div", {
    className: "additional-module-title"
  }, locales.getText('pisell2.text.others')), /*#__PURE__*/React.createElement("div", {
    className: "additional-module-buttons-container"
  }, showCashPayment && !isFullWidth ?
  /*#__PURE__*/
  // Grid布局模式：两行布局（显示现金支付模块且非全宽时）
  React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "additional-module-button-row"
  }, /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme ".concat(hasOrderNote ? 'note-button' : ''),
    onClick: function onClick() {
      handleButtonClick('order-note');
    },
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-clipboard-minus",
      className: "additional-module-button-icon"
    }),
    size: "large"
  }, locales.getText('pisell2.text.order-note'), hasOrderNote && /*#__PURE__*/React.createElement("span", {
    className: "note-indicator"
  }, /*#__PURE__*/React.createElement(Icon, {
    type: "pisell2-info-circle2"
  }))), /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme",
    onClick: function onClick() {
      handleButtonClick('split-payment');
    },
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-coins-01",
      className: "additional-module-button-icon"
    }),
    size: "large"
  }, locales.getText('split.payment'))), /*#__PURE__*/React.createElement("div", {
    className: "additional-module-button-row"
  }, /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme",
    onClick: function onClick() {
      handleButtonClick('manual-discount');
    },
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-sale-01",
      className: "additional-module-button-icon"
    }),
    size: "large"
  }, locales.getText('pisell2.text.additional-module.order-discount')), /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base ".concat(disabled ? 'disabled-theme' : 'orange-theme'),
    onClick: function onClick() {
      handleButtonClick('save-pay-later');
    },
    disabled: disabled,
    size: "large",
    icon: /*#__PURE__*/React.createElement(ClockCircleOutlined, {
      className: "additional-module-button-icon"
    })
  }, locales.getText('pisell2.text.save-pay-later')), showMore && /*#__PURE__*/React.createElement(Dropdown, {
    menu: {
      items: moreMenuItems,
      onClick: function onClick(_ref2) {
        var key = _ref2.key;
        console.log('Menu item clicked:', key);
        if (key === 'send-link') {
          if (!disabled) {
            handleButtonClick('send-link');
          } else {
            Toast.fail(locales.getText('pisell2.text.order-no-payment-cannot-send-link'));
          }
        } else if (key === 'split-payment') {
          handleButtonClick('split-payment');
        } else if (key === 'print-receipt') {
          handleButtonClick('print-receipt');
        }
      }
    },
    trigger: ['click'],
    placement: "bottomLeft",
    overlayStyle: {
      zIndex: 9999
    },
    mouseEnterDelay: 0.1,
    mouseLeaveDelay: 0.1,
    onOpenChange: function onOpenChange(open) {
      console.log('Dropdown state changed:', open);
    }
  }, /*#__PURE__*/React.createElement(Button, {
    size: "large",
    className: "additional-module-button-base more-button",
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-dots-vertical",
      size: 20
    })
  }))), !showMore && /*#__PURE__*/React.createElement("div", {
    className: "additional-module-button-row"
  }, /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme",
    onClick: function onClick() {
      handleButtonClick('send-link');
    },
    disabled: disabled,
    size: "large",
    icon: /*#__PURE__*/React.createElement(LinkOutlined, null)
  }, locales.getText('pisell2.text.send-link')), /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme",
    onClick: function onClick() {
      handleButtonClick('print-receipt');
    },
    disabled: disabled,
    size: "large",
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-printer"
    })
  }, locales.getText('pisell2.text.print-receipt')))) :
  /*#__PURE__*/
  // Flex布局模式：一行布局（不显示现金支付模块或强制全宽时）
  React.createElement("div", {
    className: "additional-module-button-row"
  }, /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme ".concat(hasOrderNote ? 'note-button' : ''),
    onClick: function onClick() {
      handleButtonClick('order-note');
    },
    size: "large",
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-clipboard-minus",
      className: "additional-module-button-icon"
    })
  }, locales.getText('pisell2.text.order-note'), hasOrderNote && /*#__PURE__*/React.createElement("span", {
    className: "note-indicator"
  }, /*#__PURE__*/React.createElement(Icon, {
    type: "pisell2-info-circle2"
  }))), /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme",
    onClick: function onClick() {
      handleButtonClick('split-payment');
    },
    size: "large",
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-coins-01",
      className: "additional-module-button-icon"
    })
  }, locales.getText('split.payment')), /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base purple-theme",
    onClick: function onClick() {
      handleButtonClick('manual-discount');
    },
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-sale-01",
      className: "additional-module-button-icon"
    }),
    size: "large"
  }, locales.getText('pisell2.text.additional-module.order-discount')), /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base ".concat(disabled ? 'disabled-theme' : 'orange-theme'),
    onClick: function onClick() {
      handleButtonClick('save-pay-later');
    },
    disabled: disabled,
    size: "large",
    icon: /*#__PURE__*/React.createElement(ClockCircleOutlined, {
      className: "additional-module-button-icon"
    })
  }, locales.getText('pisell2.text.save-pay-later')), /*#__PURE__*/React.createElement(Dropdown, {
    menu: {
      items: moreMenuItems,
      onClick: function onClick(_ref3) {
        var key = _ref3.key;
        console.log('Menu item clicked:', key);
        if (key === 'send-link') {
          if (!disabled) {
            handleButtonClick('send-link');
          } else {
            Toast.fail(locales.getText('pisell2.text.order-no-payment-cannot-send-link'));
          }
        } else if (key === 'split-payment') {
          handleButtonClick('split-payment');
        } else if (key === 'print-receipt') {
          handleButtonClick('print-receipt');
        }
      }
    },
    trigger: ['click'],
    placement: "bottomLeft",
    overlayStyle: {
      zIndex: 9999
    },
    mouseEnterDelay: 0.1,
    mouseLeaveDelay: 0.1,
    onOpenChange: function onOpenChange(open) {
      console.log('Dropdown state changed:', open);
    }
  }, /*#__PURE__*/React.createElement(Button, {
    className: "additional-module-button-base more-button",
    size: "large",
    icon: /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-dots-vertical",
      size: 20
    })
  })))));
}
export default AdditionalModule;