import { defineComponent } from "vue";
import { ElInput, ElButton } from "element-plus";
import runtime, * as RuntimeUtils from "/src/components/live-broadcast/runtime";
import styles from "./send-message.module.less";
import runtimeModel, * as RuntimeModel from './model/runtime'
import dayjs from "dayjs";


export default defineComponent({
  data() {
    return {
      message: ''
    }
  },
  methods: {
    async sendMessage() {
      try {
        await RuntimeUtils.sendMessage(this.message);
        const userInfo = RuntimeUtils.getSendMessageUser();
        // 添加一条消息记录
        RuntimeModel.addMessage({
          id: userInfo.id,
          name: userInfo.name,
          content: this.message,
          isSelf: true,
          sendTime: dayjs(new Date()).format('HH:mm:ss')
        })
        this.message = '';
      } catch (error) {
      }
    }
  },
  render() {
    return (
      <div class={styles.sendMessage}>
        <div class={styles.form}>
          <ElInput modelValue={this.message} onInput={val => this.message = val} placeholder="请输入消息" />
          <ElButton disabled={!this.message} onClick={this.sendMessage} round type="primary">发送</ElButton>
        </div>
      </div>
    )
  }
});
