<template>
	<!--  #ifdef MP-WEIXIN-->
	<ChatWxApplet ref="chatRef" @onInnerOpen="open" @onInnerError="error" @onInnerMessage="message" @onInnerFinish="finish" />
	<!--  #endif-->

	<!--  #ifdef APP-PLUS || H5-->
	<ChatAppAndWeb ref="chatRef" @onInnerOpen="open" @onInnerError="error" @onInnerMessage="message" @onInnerFinish="finish" />
	<!--  #endif-->
</template>

<script>
// #ifdef MP-WEIXIN
import ChatWxApplet from "./children/ChatWxApplet.vue";
// #endif

// #ifdef APP-PLUS || H5
import ChatAppAndWeb from "./children/ChatAppAndWeb.vue";
// #endif

export default {
	components: {
		// #ifdef MP-WEIXIN
		ChatWxApplet,
		// #endif

		// #ifdef APP-PLUS || H5
		ChatAppAndWeb,
		// #endif
	},

	methods: {
		startChat(config) {
			config["method"] = (config["method"] || "post").toUpperCase();
			config["headers"] = config["headers"] || {};
			console.log("this.$refs['chatRef']", this.$refs["chatRef"]);
			this.$refs["chatRef"].startChat(config);
		},

		stopChat(...args) {
			console.log("this.$refs['chatRef']stopChat", this.$refs["chatRef"]);
			this.$refs["chatRef"].stopChat(...args);
		},

		open(...args) {
			this.$emit("onOpen", ...args);
		},
		message(msg) {
			this.$emit("onMessage", msg);
		},
		error(...args) {
			this.$emit("onError", ...args);
		},
		finish() {
			this.$emit("onFinish");
		},
	},
};
</script>
