import type { ChatMessage } from "../model/Message";

export function useChatExportSave(options: {
  getContentHtml?: () => string;
  getExtraContentHtml?: () => string;
}) {
  const copyMessage = async(message: ChatMessage, type: 'text' | 'html' | 'markdown') => {

    function copy(data: string) {
      uni.setClipboardData({
        data: data,
        success: () => {
          uni.showToast({
            title: '复制成功',
            icon: 'success',
          });
        },
      });
    }

    switch (message.type) {
      case 'image_url': {
        uni.setClipboardData({
          data: message.image_url || ''
        });
        break;
      }
      default: {
        switch (type) {
          case 'text':
            await copy(message.content + (message.extra || ''));
            break;
          case 'html':
            await copy(`<div>${options.getContentHtml?.() || ''}</div>
    <div>${options.getExtraContentHtml?.() || ''}</div>`);
            break;
          case 'markdown':
            await copy(message.content + (message.extra || ''));
            break;
        }
        break;
      }
    }
  }

  return {
    copyMessage,
  }
}