import { h } from './chunks/d4789960.js';
import './chunks/456564be.js';
import './chunks/c26036df.js';
import { u as useEvent } from './chunks/d4058887.js';
import { a as useRef } from './chunks/4ccc6eeb.js';
import { g as getComponentOrDefine } from './chunks/071ed725.js';
import './chunks/23e44913.js';
import './chunks/d91e4e4a.js';
import './chunks/d76d6172.js';
import './kun-icon.js';
import { e as execWithSixLoad } from './chunks/cf049716.js';

var n=function(){return (n=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n}).apply(this,arguments)};function t(n,t,e,r){return new(e||(e=Promise))(function(o,i){function a(n){try{c(r.next(n));}catch(n){i(n);}}function l(n){try{c(r.throw(n));}catch(n){i(n);}}function c(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e(function(n){n(t);})).then(a,l);}c((r=r.apply(n,t||[])).next());})}function e(n,t){var e,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(i){return function(l){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;a;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(n,a);}catch(n){i=[6,n],r=0;}finally{e=o=0;}if(5&i[0])throw i[1];return {value:i[0]?i[1]:void 0,done:!0}}([i,l])}}}var r=window.location.origin,o=""+(r.indexOf("localhost")>-1?"https://www.xunlianying.vip":r);function i(t,e,r){var i={authorization:""+localStorage.getItem("AUTH")},a={authorization:""+localStorage.getItem("AUTH"),"content-type":"application/json"},l={method:"POST",body:!0!==(null==r?void 0:r.isFormData)?JSON.stringify(e):e,headers:!0!==(null==r?void 0:r.isFormData)?n(n({},i),a):i};return fetch(""+o+t,l).then(function(n){return n.json()}).catch(function(n){return n}).then(function(n){var t=n;if("4001"===String(t.code))null!=(null==r?void 0:r.callback)?r.callback():window.location.replace("/web/plume/login");else if("2001"!==t.code)throw new Error(t.msg);return n})}var a=function(n){return t(void 0,void 0,void 0,function(){return e(this,function(t){return [2,i("/horse/v1/tool/markdown",n,{isFormData:!0})]})})};

var style = ":host {\n}\n";

const KunMarkdownButton = () => {
  const refLabel = useRef();
  const uploadMarkdownEvent = useEvent("MyUpload", {
    bubbles: true,
    composed: true
  });

  const uploadFile = async event => {
    await execWithSixLoad(async () => {
      const file = event.target.files[0];
      const formData = new FormData();
      formData.set("file", file);
      const r = await a(formData);
      uploadMarkdownEvent({
        content: r.record.content
      });
    });
  };

  return h("host", null, h("style", null, style), h("span", null, h("kun-icon", {
    iconType: "markdown",
    onclick: () => refLabel.current.click(),
    iconWidth: 24,
    iconHeight: 24
  }), h("input", {
    ref: refLabel,
    type: "file",
    className: "hidden",
    onchange: uploadFile
  })));
};

KunMarkdownButton.props = {};
var kunMarkdownButton = getComponentOrDefine("kun-markdown-button", KunMarkdownButton);

export default kunMarkdownButton;
//# sourceMappingURL=kun-markdown-button.js.map
