import React, { Suspense, useEffect, useState, useRef, lazy } from 'react';
import { Meteor } from 'meteor/meteor';
import { PoblesCollection } from '/imports/api/pobles.js';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
import { Roles } from 'meteor/roles';
// import { useUserId } from 'meteor/react-meteor-accounts';
// import { Meteor } from 'meteor/meteor';
// import React, {useState, useEffect, Suspense} from 'react';
// import { useTracker, useFind } from 'meteor/react-meteor-data/suspense';
// import { FilesCol } from '/imports/api/files.js';
import { useNavigate, Link } from 'react-router-dom';
// import { Roles } from 'meteor/roles';
// import { useUserContext } from '/imports/api/contexts/AppContext';
// import { groupBy } from 'lodash';
//import Radium from 'radium';
// const IndicadorMissatges = ({notif}) => {
// return
// {notif && }
//
// ;
// };
const U = ({u, esAdministrador}) => {
const [adm, setAdm] = useState(false);
const [mon, setMon] = useState(false);
const [enc, setEnc] = useState(false);
const [vol, setVol] = useState(false);
(async () => {
const esAdmin = await Roles.userIsInRoleAsync(u._id, ["admin"]);
setAdm(esAdmin);
const esMonit = await Roles.userIsInRoleAsync(u._id, ["monitor_de_poble"], {anyScope: true});
setMon(esMonit);
const esEncar = await Roles.userIsInRoleAsync(u._id, ["encarregat_de_tasques"], {anyScope: true});
setEnc(esEncar);
const esVolun = await Roles.userIsInRoleAsync(u._id, ["voluntari_de_poble"], {anyScope: true});
setVol(esVolun);
// setEsAdministrador(comprovaAdmin);
})();
// console.log("adm: ", adm);
// console.log("mon: ", mon);
// console.log("enc: ", enc);
// console.log("vol: ", vol);
// const [esAdministrador, setEsAdministrador] = useState(false);
// const u = useTracker("user", async () => await Meteor.userAsync());
// const userId = Meteor.userId();
// useEffect(() => {
// (async () => {
// const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
// setEsAdministrador(comprovaAdmin);
// })();
// }, [Meteor.userId()]);
// const u = useUserContext();
// console.log("UUU: ", u);
const navigate = useNavigate();
// const files = useTracker(() => {
// const filesHandle = Meteor.subscribe('files.avatar');
// // const docsReadyYet = filesHandle.ready();
// const files = FilesCol?.find({"meta.userId": Meteor.userId()}, {sort: {name: 1}}).fetch(); // Meteor.userId() ?? "nop"
// return files;
// });
// const uname = useTracker(() => Meteor.user({ fields: { 'username': 1 } })?.username );
// const [mostraMenu, setMostraMenu] = useState(false);
//const avatarLink = u.avatarLink;
// alert("avLnk: ", u.profile.avatarLink);
return
{u?.username}
{
ev.preventDefault();
ev.stopPropagation();
alert("Click en missatges");
}}
>
{/*