"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

var _antd = require("antd");

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

var _CouponTable = _interopRequireDefault(require("./CouponTable"));

var _FilteredProductModal = _interopRequireDefault(require("./FilteredProductModal"));

var _ProductDetailPage = _interopRequireDefault(require("./ProductDetailPage"));

var _FunctionTable = _interopRequireDefault(require("./FunctionTable"));

var _CatgTable = _interopRequireDefault(require("./CatgTable"));

var _CustomTable = _interopRequireDefault(require("./CustomTable"));

require("./index.less");

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 _getRequireWildcardCache(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; }

var LinkModal = function LinkModal(props) {
  var onConfirm = props.onConfirm,
      onClose = props.onClose,
      visible = props.visible;

  var _a = (0, _react.useState)(''),
      linkUrl = _a[0],
      setLinkUrl = _a[1];

  var _b = (0, _react.useState)('Category'),
      selected = _b[0],
      setSelected = _b[1];

  var list = ['Category', 'Customized Page', 'Product Details Page', 'Filtered Products', 'Function Page', 'Coupons'];

  var _c = (0, _react.useState)(0),
      total = _c[0],
      setTotal = _c[1];

  (0, _react.useEffect)(function () {
    setTotal(0);
  }, [visible]);

  var onModalSava = function onModalSava() {
    if (onConfirm) {
      onConfirm(linkUrl);
    }

    if (onClose) {
      onClose();
    }
  };

  return /*#__PURE__*/_react["default"].createElement(_antd.Modal, {
    cancelText: "Cancel",
    draggable: false,
    footer: null,
    okText: "OK",
    onCancel: onClose,
    onOk: onConfirm,
    title: "URL Setup",
    visible: visible,
    width: "1000",
    wrapClassName: "linkModal"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "modalWrap"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "linkType"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "typeTitle"
  }, "Link Type:"), list.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: index,
      className: "typeItem " + (selected === item ? 'selected' : ''),
      onClick: function onClick() {
        return setSelected(item);
      }
    }, item);
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "content"
  }, selected === 'Category' && /*#__PURE__*/_react["default"].createElement(_CatgTable["default"], {
    onChange: function onChange(value) {
      return setLinkUrl(value);
    }
  }), selected === 'Customized Page' && /*#__PURE__*/_react["default"].createElement(_CustomTable["default"], {
    onChange: function onChange(value) {
      return setLinkUrl(value);
    }
  }), selected === 'Product Details Page' && /*#__PURE__*/_react["default"].createElement(_ProductDetailPage["default"], {
    setUrl: function setUrl(url) {
      return setLinkUrl(url);
    }
  }), selected === 'Filtered Products' && /*#__PURE__*/_react["default"].createElement(_FilteredProductModal["default"], {
    onDataChange: function onDataChange(url, t) {
      setLinkUrl(url);
      setTotal(t);
    }
  }), selected === 'Function Page' && /*#__PURE__*/_react["default"].createElement(_FunctionTable["default"], {
    onChange: function onChange(value) {
      return setLinkUrl(value);
    }
  }), selected === 'Coupons' && /*#__PURE__*/_react["default"].createElement(_CouponTable["default"], {
    onChange: function onChange(value) {
      return setLinkUrl(value);
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "footer"
  }, selected === 'Filtered Products' ? /*#__PURE__*/_react["default"].createElement("div", {
    className: "total"
  }, total, " Products In Total") : /*#__PURE__*/_react["default"].createElement("div", null), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_antd.Button, {
    className: "btn-cancel",
    onClick: function onClick() {
      return onClose && onClose();
    }
  }, "Cancel"), /*#__PURE__*/_react["default"].createElement(_antd.Button, {
    className: "btn-confirm",
    onClick: onModalSava,
    type: "primary"
  }, "OK")))));
};

var _default = LinkModal;
exports["default"] = _default;