'use strict';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { initCommentList, getUserDisplayText } from './CommentList.funcs.js';
import { CommentComponent } from './Comment.js';
import { useAsyncEffect } from '../../../fd-toolbox/hooks/use-async-effect.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function CommentList(t0) {
  const $ = c(7);
  const {
    resources,
    uiResourceMeta,
    resourceName,
    resourceId
  } = t0;
  const [comments, setComments] = useState(resources);
  const [uiResourceMetaState, setUiResourceMetaState] = useState(uiResourceMeta);
  let t1;
  if ($[0] !== resourceId || $[1] !== resourceName || $[2] !== resources || $[3] !== uiResourceMetaState) {
    t1 = async () => {
      await initCommentList(setComments, setUiResourceMetaState, uiResourceMetaState, resourceId, resources, resourceName);
    };
    $[0] = resourceId;
    $[1] = resourceName;
    $[2] = resources;
    $[3] = uiResourceMetaState;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  useAsyncEffect(t1);
  let t2;
  if ($[5] !== comments) {
    t2 = jsx("div", {
      className: "flex w-full flex-col gap-4",
      children: comments?.map(_temp)
    });
    $[5] = comments;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  return t2;
}
function _temp(comment) {
  const user = comment.user;
  const userName = getUserDisplayText(user?.firstName, user?.lastName);
  return jsx(CommentComponent, {
    body: comment.body,
    userName,
    userImageUrl: user?.imageUrl
  }, comment.id);
}
__name(CommentList, "CommentList");

export { CommentList };
