import { locales } from "@pisell/utils";
import { getHandleSetClient } from "../../../booking/info2/cartClientCard/utils";
import { getHandleSetService } from "../../components/addServiceVariant/utils";
import { useToast } from '@pisell/materials';
var useScanGlobalHandle = function useScanGlobalHandle() {
  var Toast = useToast();
  var walletHandle = function walletHandle(data) {
    var handleSetClient = getHandleSetClient();
    if (!data.data) {
      Toast.fail(locales.getText('pisell2.text.scan-global-failed'));
      return;
    }
    if (handleSetClient && data.data) {
      handleSetClient(data.data);
    }
  };
  var walletPassHandle = function walletPassHandle(data) {
    var handleSetClient = getHandleSetClient();
    if (!data.data) {
      Toast.fail(locales.getText('pisell2.text.scan-global-failed'));
      return;
    }
    if (handleSetClient && data.data) {
      handleSetClient(data.data, {
        fullData: data
      });
    }
  };
  var productHandle = function productHandle(data) {
    var _data$data, _data$data2;
    var handleSetService = getHandleSetService();
    if (!((_data$data = data.data) !== null && _data$data !== void 0 && _data$data.list)) {
      Toast.fail(locales.getText('pisell2.text.scan-global-failed'));
      return;
    }
    if (handleSetService && data !== null && data !== void 0 && (_data$data2 = data.data) !== null && _data$data2 !== void 0 && _data$data2.list) {
      handleSetService(data.data.list, data.scanCode);
    }
  };
  var handleScan = function handleScan(data) {
    if (data.searchType === 'wallet') {
      walletHandle(data);
    } else if (data.searchType === 'walletPass') {
      walletPassHandle(data);
    } else if (data.searchType === 'product' || data.searchType === 'local_product') {
      productHandle(data);
    }
  };
  return handleScan;
};
export default useScanGlobalHandle;