/*
 * @Author: thy
 * @Date: 2023-10-31 09:33:14
 * @LastEditors: thy
 * @LastEditTime: 2023-11-02 17:17:32
 * @Description: file content
 * @FilePath: \dsk-operate-ui\src\components\JsComponents\MaxPageSizeTip.js
 */

import styled from "vue-styled-components";
import Vue from "vue";
import { v4 } from "uuid";
import maxTipTitleIcon from "@/assets/images/market/max-tip-title-icon.svg";
import closeMaxTipIcon from "@/assets/images/market/close-max-tip-icon.svg";

const maxPageSizeTipContainer = styled.div`
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1200;
`;


const maxPageTipContainer = styled.div`
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 340px;
    height: 112px;
    background: #ffffff;
    border: 1px solid #e5e6eb;
    box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 20px;
    box-sizing: border-box;

    .top-title-container {
      display: flex;
      align-items: center;

      .max-tip-icon {
        width: 24px;
        height: 24px;
      }

      .tip-title {
        color: #1d2129;
        font-size: 16px;
        line-height: 24px;
        font-weight: 400;
        margin-left: 16px;
        margin-right: 16px;
        width: 228px;
      }

      .max-tip-close-icon {
        width: 16px;
        height: 16px;
        align-self: flex-start;
        cursor: pointer;
      }
    }

    .max-page-tip-content {
      margin-top: 4px;
      padding-left: 40px;
      padding-right: 32px;
      box-sizing: border-box;

      .max-page-content-inner {
        color: #1d2129;
        font-size: 14px;
        line-height: 22px;
      }
    }
`;


const MaxPageSizeTip = {
  name: "maxPageSizeTip",
  render(createElement) {
    return (
      <transition name="fade" mode="out-in" appear>
        <maxPageSizeTipContainer vOn:click_stop={this.closeMaxTip.bind()} class="max-page-size-tip">
          <maxPageTipContainer vOn:click_stop={""}>
            <div class="max-page-tip-inner">
              <div class="top-title-container">
                <img src={maxTipTitleIcon} alt="" class="max-tip-icon"></img>
                <span class="tip-title">数据查询已达到上限</span>
                <img src={closeMaxTipIcon} alt="" class="max-tip-close-icon" vOn:click_stop={this.closeMaxTip.bind()}></img>
              </div>
              <div class="max-page-tip-content">
                <div class="max-page-content-inner">
                  {this.msg}
                </div>
              </div>
            </div>
          </maxPageTipContainer>
        </maxPageSizeTipContainer>
      </transition>
    );
  },
};

/**
 * 
 * @param {string} msg 展示的信息
 * @param {Function} closeHandle 关闭弹窗的回调
 * @returns 
 */
function showMaxPageSizeTip(msg = "") {
  return new Promise((resolve, reject) => {
    try {
      // 生成构造函数
      const maxMsgBox = Vue.extend(MaxPageSizeTip);
      // 实例化
      const instance = new maxMsgBox({
        data() {
          return {
            msg
          };
        },
        methods: {
          // 关闭弹窗
          closeMaxTip() {
            resolve({
              uid: v4(),
              done: this.doneHandle
            });
          },
          // 关闭回调
          doneHandle() {
            // 卸载组件
            instance.$destroy();
            instance.$el.remove();
          }
        },
      });
      // 初始化组件
      instance.$mount();
      // 添加到body中
      document.body.appendChild(instance.$el);
    } catch (error) {
      reject(error);
    }
  });
}

export default showMaxPageSizeTip;

