
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/


/**
 * AUTO-GENERATED FILE. DO NOT MODIFY.
 */

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { each } from 'tvrender/lib/core/util.js';
import env from 'tvrender/lib/core/env.js';
function formatAmount(amount, decimalPlaces) {
  if (decimalPlaces === void 0) {
    decimalPlaces = 2;
  }
  if (amount === 0) return "0";
  var units = [{
    value: 1,
    symbol: ""
  }, {
    value: 1e3,
    symbol: "K"
  }, {
    value: 1e6,
    symbol: "M"
  }
  // { value: 1e9, symbol: "B" },
  // { value: 1e12, symbol: "T" },
  ];
  // 找到合适的单位
  var selectedUnit = units[0];
  for (var i = units.length - 1; i >= 0; i--) {
    if (amount >= units[i].value) {
      selectedUnit = units[i];
      break;
    }
  }
  // 格式化数字
  var formattedValue = (amount / selectedUnit.value).toFixed(decimalPlaces);
  // 移除不必要的小数部分（如.0）
  var cleanValue = formattedValue.replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1");
  return "" + cleanValue + selectedUnit.symbol;
}
function formatTimestamp(timestamp) {
  var date = new Date(timestamp);
  // 月份名称映射
  var months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
  // 星期几名称映射
  var weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  // 获取日期各部分
  var month = months[date.getMonth()];
  var day = date.getDate();
  var weekday = weekdays[date.getDay()];
  // 格式化时间部分
  var hours = date.getHours().toString().padStart(2, '0');
  var minutes = date.getMinutes().toString().padStart(2, '0');
  var time = hours + ":" + minutes;
  return "" + month + day + "\u65E5" + weekday + " " + time;
}
var margin = 10;
var TooltipHTMLContent = /** @class */function () {
  function TooltipHTMLContent(api) {
    this._show = false;
    this._enterable = true;
    if (env.wxa) {
      return null;
    }
    var el = document.createElement('div');
    // TODO: TYPE
    el.domBelongToZr = true;
    this.el = el;
    // const zr = this._zr = api.getZr();
    var container = api.getDom();
    (container || api.getDom()).appendChild(el);
    el.onmouseenter = function () {
      api.dispatchAction({
        type: 'updateAxisPointer',
        currTrigger: 'globalout'
      });
    };
    this._api = api;
    this._container = container;
  }
  TooltipHTMLContent.prototype.show = function (_a) {
    var isUp = _a.isUp,
      orders = _a.orders,
      time = _a.time,
      x = _a.x,
      y = _a.y,
      precision = _a.precision;
    this._show = true;
    var el = this.el;
    var style = el.style;
    style.position = "absolute";
    style.left = x + margin + "px";
    style.top = y - margin + "px";
    style.visibility = "visible";
    style.opacity = "1";
    var isMuti = orders.length > 1;
    var formatTime = formatTimestamp(time * 1000);
    var order = orders[0];
    var title = formatAmount(order.size) + " @ " + order.price.toFixed(precision) + "<span style=\"margin-left: 12px; color: var(--placeholder-text-color);\">" + formatTime + "</span>";
    var ordersHtml = '';
    if (isMuti) {
      var totalPrice_1 = 0;
      var totalSize_1 = 0;
      ordersHtml = "<div style=\"margin-bottom: 12px; font-size: 12px; color: var(--placeholder-text-color);\">TRADES</div>";
      each(orders, function (item) {
        totalPrice_1 = totalPrice_1 + item.price;
        totalSize_1 += item.size;
        ordersHtml = ordersHtml + "<div style=\"height: 18px; margin-bottom: 2px; font-size: 12px; margin-left: 4px;\">" + formatAmount(item.size) + " @ " + item.price.toFixed(precision) + "<span style=\"margin-left: 12px; color: var(--placeholder-text-color);\">" + formatTime + "</span></div>";
      });
      title = formatAmount(totalSize_1) + " @ " + (totalPrice_1 / orders.length).toFixed(precision) + " avg price";
    }
    var primaryColor = isUp ? "--primary-color" : "--color-kl-red";
    el.innerHTML = "<div style=\"padding-left: 4px;border-left: 4px solid var(" + primaryColor + ");width: 290px;z-index: 10;border-radius: 6px;background: var(--container-bg);box-shadow: rgba(0, 0, 0, 0.4) 0px 2px 4px 0px;color: var(--title-color);\">\n        <div style=\"padding: 16px 12px;\"><div style=\"display: flex; align-items: center; margin-bottom: 12px;\">\n        <div style=\"height: 20px; border-radius: 50px; min-width: 20px; margin-right: 8px; text-align: center; background-color: var(" + primaryColor + "); font-size: 12px; color: #fff;line-height:20px;\">" + orders.length + "</div>\n        <div style=\"font-weight: 600; font-size: 18px;\">" + (isUp ? '买入' : '卖出') + "</div></div><div style=\"font-size: 13px; margin-bottom: 12px;\">" + title + "</div>\n        " + ordersHtml + "\n        </div>\n        </div>\n        ";
    if (x + el.clientWidth > this._container.clientWidth) {
      style.left = x - el.clientWidth - margin + 'px';
    }
    if (y + el.clientHeight > this._container.clientHeight) {
      style.top = y - el.clientHeight - margin + 'px';
    }
  };
  TooltipHTMLContent.prototype.getSize = function () {
    var el = this.el;
    return [el.offsetWidth, el.offsetHeight];
  };
  TooltipHTMLContent.prototype.hide = function () {
    if (!this._show) {
      return;
    }
    var style = this.el.style;
    style.visibility = 'hidden';
    style.opacity = '0';
    env.transform3dSupported && (style.willChange = '');
    this._show = false;
  };
  TooltipHTMLContent.prototype.isShow = function () {
    return this._show;
  };
  TooltipHTMLContent.prototype.dispose = function () {
    var parentNode = this.el.parentNode;
    parentNode && parentNode.removeChild(this.el);
    this.el = this._container = null;
  };
  return TooltipHTMLContent;
}();
export default TooltipHTMLContent;