import { h } from './d4789960.js';
import { u as useProp } from './c26036df.js';
import { u as useEvent } from './d4058887.js';
import { a as useState } from './f180b4ff.js';
import { g as getComponentOrDefine } from './071ed725.js';
import { t as toastr } from './d91e4e4a.js';
import { O as Option } from './a02c5734.js';
import '../kun-image-or-default.js';
import { d as dayjs_min, g as getKunImageUrl } from './8778f710.js';
import { u as useHoverHook } from './507803b4.js';
import '../kun-input-comment.js';
import { e as execWithSixLoad } from './2966930b.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{u(r.next(n));}catch(n){i(n);}}function c(n){try{u(r.throw(n));}catch(n){i(n);}}function u(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e(function(n){n(t);})).then(a,c);}u((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:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){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,c])}}}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"},c={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,c).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/card/comment/create",n)]})})};

var style = ":host {\n}\n\n.fixed-width {\n  width: 100px !important;\n}\n\n.text-color-username {\n  color: #008cd2;\n}\n";

const toastrMsg = string => {
  toastr.info(Option.of(string).getOrElse("操作成功"));
};

const formatDate = date => dayjs_min(date).format("YYYY-MM-DD");

const KunChildCommentItemComp = () => {
  const [itemProps, setItemProps] = useProp("kunItem");
  const [firstCommentId] = useProp("firstCommentId");
  const [seriesId] = useProp("seriesId");
  const [hoverRef, isHovered] = useHoverHook();
  const toogleCurrentCommentEvent = useEvent("MyChange", {
    composed: true,
    bubbles: true
  });
  const item = Option.of(itemProps).getOrElse({
    content: "ok",
    createAt: 1,
    parentUserName: "ddd",
    commentUserName: "caedman"
  });
  const [showResponse, setShowReponse] = useState(false);

  const onHandleChildComment = async event => {
    const data = {
      postId: item.postId,
      parentCommentId: item.commentId,
      firstCommentId: item.parentCommentId,
      seriesId,
      content: event.detail.text
    };
    await execWithSixLoad(async () => {
      await a(data);
      toastrMsg("评论成功");
    });
  };

  return h("host", null, h("style", null, style), h("div", {
    class: "flex flex-row w-full flex-1",
    ref: hoverRef
  }, h("div", {
    class: "flex-none flex w-16"
  }, h("kun-image-or-default", {
    url: getKunImageUrl(item.commentUserAvatarOpt),
    width: 56,
    height: 56
  })), h("div", {
    class: "flex w-full flex-col flex-auto pt-4"
  }, h("div", {
    class: "flex flex-row w-full justify-between"
  }, h("div", {
    class: "flex justify-start w-full"
  }, h("span", {
    class: "text-color-username mr-2"
  }, item.commentUserName), "\u56DE\u590D", h("span", {
    class: "text-color-username mr-2"
  }, item.parentUserName), ":", h("span", null, item.content)), h("span", {
    class: "w-32 flex justify-end"
  }, formatDate(item.createAt))), h("div", {
    class: "w-full h-5 justify-end flex py-8"
  }, h("span", {
    class: "cursor-pointer",
    onclick: () => {
      setShowReponse(true);
      toogleCurrentCommentEvent(item.commentId);
    }
  }, "\u56DE\u590D")), h("div", {
    class: "flex flex-col flex-auto w-full justify-between"
  }, showResponse && h("div", {
    class: "flex w-full"
  }, h("kun-input-comment", {
    onMySubmit: onHandleChildComment,
    onMyCancel: () => setShowReponse(false),
    className: "flex w-1 w-full flex-auto box-border w-1 fixed-width"
  }))))));
};

KunChildCommentItemComp.props = {
  firstCommentId: {
    type: String
  },
  seriesId: {
    type: String
  },
  kunItem: {
    type: Object
  }
};
var kunChildCommentItemComp = getComponentOrDefine("kun-child-comment-item-comp", KunChildCommentItemComp);

export { a, formatDate as f, kunChildCommentItemComp as k };
//# sourceMappingURL=1971edde.js.map
