function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { Navigation } from 'react-native-navigation';
import appStore from './screens/AppStore';
// import {ChatStack} from './App.js'
import { ListChatScreen } from './screens/listchat';
import { ChatScreen } from './screens/chat';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
import * as MyAsyncStorage from './utils/MyAsyncStorage';
import { USER } from './utils/MyAsyncStorage';
import socket from './socket';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import hoistNonReactStatics from 'hoist-non-react-statics';
import colors from './Styles';
import React from 'react';
import { StatusBar } from 'react-native';
import { AttachsScreen } from './screens/attachs';
import BottomSheetChatOptions from './components/bottomSheetChatOptions';
import listChatStore from './screens/listchat/ListChatStore';
function safeAreaProviderHOC(Component) {
  function Wrapper(props) {
    return /*#__PURE__*/React.createElement(SafeAreaProvider, {
      style: [{
        flex: 1
      }]
    }, /*#__PURE__*/React.createElement(StatusBar, {
      backgroundColor: colors.primary
    }), /*#__PURE__*/React.createElement(Component, props));
  }
  Wrapper.displayName = `safeAreaProviderHOC(${Component.displayName || Component.name})`;

  // @ts-ignore - hoistNonReactStatics uses old version of @types/react
  hoistNonReactStatics(Wrapper, Component);
  return Wrapper;
}
class ChatVT {
  constructor() {
    _defineProperty(this, "AsyncStorage", void 0);
    _defineProperty(this, "interval", void 0);
    _defineProperty(this, "toChatWithCustomer", async (componentId, order, type) => {
      appStore.createConversation({
        order_number: order.ma_phieugui,
        chat_type: type
      }, conversation => {
        Navigation.push(componentId, {
          component: {
            name: 'ChatScreen',
            options: {
              popGesture: false,
              bottomTabs: {
                visible: false
              },
              topBar: {
                visible: false,
                height: 0
              }
            },
            passProps: {
              data: conversation,
              order: order
            }
          }
        });
      }, error => alert(error));
    });
  }
  registerScreen() {
    Navigation.registerComponent('ListChatScreen', () => gestureHandlerRootHOC(safeAreaProviderHOC(ListChatScreen)));
    Navigation.registerComponent('ChatScreen', () => gestureHandlerRootHOC(safeAreaProviderHOC(ChatScreen)));
    Navigation.registerComponent('AttachsScreen', () => gestureHandlerRootHOC(safeAreaProviderHOC(AttachsScreen)));
    const screenEventListener = Navigation.events().registerComponentDidAppearListener(_ref => {
      var _listChatStore$data;
      let {
        componentId,
        componentName,
        passProps
      } = _ref;
      if (componentName === 'navigation.VTMan.MessengerScreen.TK' && ((_listChatStore$data = listChatStore.data) === null || _listChatStore$data === void 0 ? void 0 : _listChatStore$data.length) === 0) {
        listChatStore.page = 0;
        listChatStore.getData({});
      }
    });
    // screenEventListener.remove();
  }

  /** */
  init(env, storage, lang, appId, token, tokenSSO, onSuccess, onError) {
    this.registerScreen();
    this.AsyncStorage = storage;
    appStore.appId = appId;
    appStore.env = env;
    appStore.changeLanguage(lang);
    appStore.Auth({
      token: token,
      token_sso: tokenSSO
    }, res => {
      var _listChatStore$data2;
      // if(this.interval){
      //   clearInterval(this.interval)
      // }
      // this.interval = setInterval(()=>{
      //   appStore.onlineState()
      // }, 30000)
      if (((_listChatStore$data2 = listChatStore.data) === null || _listChatStore$data2 === void 0 ? void 0 : _listChatStore$data2.length) === 0) {
        listChatStore.page = 0;
        listChatStore.getData({});
      }
      if (onSuccess) onSuccess(res);
    }, onError);
  }
  toListChat(componentId) {
    appStore.componentId = componentId;
    Navigation.push(componentId, {
      component: {
        name: 'ListChatScreen',
        options: {
          popGesture: false,
          bottomTabs: {
            visible: false
          },
          topBar: {
            visible: false,
            height: 0
          }
        }
      }
    });
  }
  toChat(componentId, orderChat) {
    appStore.componentId = componentId;
    if (orderChat) {
      appStore.createConversation({
        vtm_user_ids: orderChat.vtm_user_ids,
        order_number: orderChat.order_number
      }, conversation => {
        Navigation.push(componentId, {
          component: {
            name: 'ChatScreen',
            options: {
              popGesture: false,
              bottomTabs: {
                visible: false
              },
              topBar: {
                visible: false,
                height: 0
              }
            },
            passProps: {
              data: conversation,
              order: orderChat === null || orderChat === void 0 ? void 0 : orderChat.order
            }
          }
        });
      }, error => alert(error));
    }
  }
  chatWithReceiver(componentId, order) {
    appStore.componentId = componentId;
    if (order !== null && order !== void 0 && order.ORDER_NUMBER) {
      appStore.createConversationWithReceiver({
        order_number: order === null || order === void 0 ? void 0 : order.ORDER_NUMBER
      }, conversation => {
        Navigation.push(componentId, {
          component: {
            name: 'ChatScreen',
            options: {
              popGesture: false,
              bottomTabs: {
                visible: false
              },
              topBar: {
                visible: false,
                height: 0
              }
            },
            passProps: {
              data: conversation,
              order: order
            }
          }
        });
      }, error => alert(error));
    }
  }
  chatWithCS(componentId, order) {
    appStore.componentId = componentId;
    appStore.createConversationWithCS({
      order_number: order === null || order === void 0 ? void 0 : order.ORDER_NUMBER
    }, conversation => {
      Navigation.push(componentId, {
        component: {
          name: 'ChatScreen',
          options: {
            popGesture: false,
            bottomTabs: {
              visible: false
            },
            topBar: {
              visible: false,
              height: 0
            }
          },
          passProps: {
            data: conversation
          }
        }
      });
    }, error => alert(error));
  }
  handleNotification(env, storage, lang, appId, token, tokenSSO, onSuccess, onError, componentId, conversation_id) {
    if (!appStore.user.token) {
      this.init(env, storage, lang, appId, token, tokenSSO, () => {
        appStore.conversationDetail({
          conversation_id: conversation_id
        }, conversation => {
          Navigation.push(componentId, {
            component: {
              name: 'ChatScreen',
              options: {
                popGesture: false,
                bottomTabs: {
                  visible: false
                },
                topBar: {
                  visible: false,
                  height: 0
                }
              },
              passProps: {
                data: conversation
              }
            }
          });
        });
      }, onError);
    } else {
      appStore.conversationDetail({
        conversation_id: conversation_id
      }, conversation => {
        Navigation.push(componentId, {
          component: {
            name: 'ChatScreen',
            options: {
              popGesture: false,
              bottomTabs: {
                visible: false
              },
              topBar: {
                visible: false,
                height: 0
              }
            },
            passProps: {
              data: conversation
            }
          }
        });
      });
    }
  }

  /** Lang: 'VN' | 'EN' */
  changeLanguage(lang) {
    appStore.changeLanguage(lang);
  }
  loginAdmin(componentId, storage, username, password, onSuccess, onError) {
    appStore.componentId = componentId;
    this.registerScreen();
    appStore.loginAdmin({
      username,
      password
    }, async data => {
      this.AsyncStorage = storage;
      appStore.appId = 'Admin';
      appStore.env = 'DEV';
      appStore.changeLanguage('VI');
      await MyAsyncStorage.save(USER, data);
      await socket.init();
      Navigation.push(componentId, {
        component: {
          name: 'ListChatScreen',
          options: {
            popGesture: false,
            bottomTabs: {
              visible: false
            },
            topBar: {
              visible: false,
              height: 0
            }
          }
        }
      });
    });
  }
  loginVTP(componentId, storage, username, password, onSuccess, onError) {
    Navigation.registerComponent('ListChatScreen', () => gestureHandlerRootHOC(ListChatScreen));
    Navigation.registerComponent('ChatScreen', () => gestureHandlerRootHOC(ChatScreen));
    appStore.loginVTP({
      username,
      password
    }, async data => {
      this.init('DEV', storage, 'VN', 'VTPost', data.TokenKey, data.TokenSSO, onSuccess);
    });
  }
  loginVTM(componentId, storage, username, password, onSuccess, onError) {
    this.registerScreen();
    appStore.loginVTM({
      phone: username,
      ma_buucuc: password
    }, async data => {
      this.init('DEV', storage, 'VN', 'VTMan', data.token, '', onSuccess);
    });
  }
  vtpWithCS(componentId, order_number) {
    appStore.vtpWithCS({
      order_number
    }, async data => {
      Navigation.push(componentId, {
        component: {
          name: 'ChatScreen',
          options: {
            popGesture: false,
            bottomTabs: {
              visible: false
            },
            topBar: {
              visible: false,
              height: 0
            }
          },
          passProps: {
            data: data
          }
        }
      });
    });
  }
  vtmWithCS(componentId, order_number) {
    appStore.vtmWithCS({
      order_number
    }, async data => {
      Navigation.push(componentId, {
        component: {
          name: 'ChatScreen',
          options: {
            popGesture: false,
            bottomTabs: {
              visible: false
            },
            topBar: {
              visible: false,
              height: 0
            }
          },
          passProps: {
            data: data
          }
        }
      });
    });
  }
}
export const chatVT = new ChatVT();
export const ListChat = ListChatScreen;
export const BottomSheetChat = BottomSheetChatOptions;
//# sourceMappingURL=index.js.map