import React from 'react';
import { locales } from '@pisell/utils';
import { Button, Icon } from '@pisell/materials';
import "./index.less";
import { useGetApp, useGetGoalShopInfo, useLanguage, useModal } from "../hooks";
import localeTexts from "../locales";
import { CUP_PROJECT_FOOTER_BUTTONS } from "./const";
import SearchBar from "../components/SearchBar";
import AddCustomerModal from "../components/AddCustomerModal";
import CustomerAndCupModal from "../components/CustomerAndCupModal";
import SettingModal from "../components/SettingModal";
var SCAN_LISTENER_KEY = 'eco-cup-project-scan-listener';
export default function EcoCupProject() {
  var language = useLanguage();
  locales.init(localeTexts, language);
  var getApp = useGetApp();
  var addCustomerModal = useModal('ecocup-add-customer-modal');
  var settingModal = useModal('ecocup-setting-modal');
  var customerAndCupModal = useModal('ecocup-customer-and-cup-modal');
  var _useGetGoalShopInfo = useGetGoalShopInfo(),
    goalShopId = _useGetGoalShopInfo.goalShopId;
  var onSearchResult = function onSearchResult(result) {
    console.log('onSearchResult', result);
    if ((result === null || result === void 0 ? void 0 : result.type) === 'customer') {
      customerAndCupModal.open({
        data: {
          firstType: result === null || result === void 0 ? void 0 : result.type,
          customerData: result === null || result === void 0 ? void 0 : result.data
        }
      });
    } else if ((result === null || result === void 0 ? void 0 : result.type) === 'cup') {
      customerAndCupModal.open({
        data: {
          firstType: result === null || result === void 0 ? void 0 : result.type,
          cupData: result === null || result === void 0 ? void 0 : result.data
        }
      });
    }
  };
  var onClickNewCustomer = function onClickNewCustomer() {
    console.log('onClickNewCustomer');
    addCustomerModal.open();
  };
  var onClickSetting = function onClickSetting() {
    console.log('onClickSetting');
    settingModal.open();
  };
  var onClickCustomerList = function onClickCustomerList() {
    console.log('onClickCustomerList');
    var app = getApp === null || getApp === void 0 ? void 0 : getApp();
    if (goalShopId) {
      var _app$history;
      app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 || _app$history.push("/ecocup/customer-list?goal_shop_id=".concat(goalShopId));
    } else {
      var _app$history2;
      app === null || app === void 0 || (_app$history2 = app.history) === null || _app$history2 === void 0 || _app$history2.push('/ecocup/customer-list');
    }
  };
  var onClickCupList = function onClickCupList() {
    console.log('onClickCupList');
    var app = getApp === null || getApp === void 0 ? void 0 : getApp();
    if (goalShopId) {
      var _app$history3;
      app === null || app === void 0 || (_app$history3 = app.history) === null || _app$history3 === void 0 || _app$history3.push("/ecocup/cup-list?goal_shop_id=".concat(goalShopId));
    } else {
      var _app$history4;
      app === null || app === void 0 || (_app$history4 = app.history) === null || _app$history4 === void 0 || _app$history4.push('/ecocup/cup-list');
    }
  };
  var onClickButton = function onClickButton(key) {
    switch (key) {
      case 'add-new-customer':
        onClickNewCustomer();
        break;
      case 'customer-list':
        onClickCustomerList();
        break;
      case 'cup-list':
        onClickCupList();
        break;
      case 'setting':
        onClickSetting();
        break;
    }
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "ecocup-cup-project"
  }, /*#__PURE__*/React.createElement("div", {
    className: "ecocup-cup-project-title"
  }, locales.getText('pisell2.text.cup-project.title')), /*#__PURE__*/React.createElement("div", {
    className: "ecocup-cup-project-search-bar"
  }, /*#__PURE__*/React.createElement(SearchBar, {
    scanListenerKey: SCAN_LISTENER_KEY,
    onSearchResult: onSearchResult
  })), /*#__PURE__*/React.createElement("div", {
    className: "ecocup-cup-project-actions"
  }, CUP_PROJECT_FOOTER_BUTTONS.map(function (button) {
    return /*#__PURE__*/React.createElement(Button, {
      key: button.key,
      type: button.type,
      size: "large",
      icon: /*#__PURE__*/React.createElement(Icon, {
        type: button.icon,
        size: 32
      }),
      onClick: function onClick() {
        return onClickButton(button.key);
      },
      className: "ecocup-cup-project-actions-button"
    }, locales.getText(button.languageKey));
  })), addCustomerModal.visible && /*#__PURE__*/React.createElement(AddCustomerModal, addCustomerModal.modalProps), customerAndCupModal.visible && /*#__PURE__*/React.createElement(CustomerAndCupModal, customerAndCupModal.modalProps), settingModal.visible && /*#__PURE__*/React.createElement(SettingModal, settingModal.modalProps));
}