import moment from "moment-timezone";
import PhoneNum from "awesome-phonenumber";
let regionNames = new Intl.DisplayNames(["en"], {
  type: "region",
});
const handler = async (m, { conn, text, usedPrefix, command: cmd }) => {
  let num = text || m.mentionedJid?.[0] || m.quoted?.sender;
  if (!num) throw `Ex: ${usedPrefix + cmd} @tag / 628xxx`;
  if (
    ((num = num.replace(/\D/g, "") + "@s.whatsapp.net"),
    !(await conn.onWhatsApp(num))[0]?.exists)
  )
    throw "User not exists";
  let img = await conn
      .profilePictureUrl(num, "image")
      .catch((_) => "./src/avatar_contact.png"),
    bio = await conn.fetchStatus(num).catch((_) => {}),
    name = conn.getName(num),
    business = await conn.getBusinessProfile(num),
    format = PhoneNum(`+${num.split("@")[0]}`),
    wea = `\t\t\t\t*▾ WHATSAPP ▾*\n\n*° Country :* ${regionNames.of(format.getRegionCode("international")).toUpperCase()}\n*° Name :* ${name || "-"}\n*° Format Number :* ${format.getNumber("international")}\n*° Url Api :* wa.me/${num.split("@")[0]}\n*° Mentions :* @${num.split("@")[0]}\n*° Status :* ${bio?.status || "-"}\n*° Date Status :* ${bio?.setAt ? moment(bio.setAt.toDateString()).locale("id").format("LL") : "-"}\n\n${business ? `\t\t\t\t*▾ INFO BUSINESS ▾*\n\n*° BusinessId :* ${business.wid}\n*° Website :* ${business.website ? business.website : "-"}\n*° Email :* ${business.email ? business.email : "-"}\n*° Category :* ${business.category}\n*° Address :* ${business.address ? business.address : "-"}\n*° Timeone :* ${business.business_hours.timezone ? business.business_hours.timezone : "-"}\n*° Descripcion* : ${business.description ? business.description : "-"}` : "*Standard WhatsApp Account*"}`;
  img
    ? await conn.sendMessage(
        m.chat,
        {
          image: {
            url: img,
          },
          caption: wea,
          mentions: [num],
        },
        {
          quoted: m,
        },
      )
    : m.reply(wea);
};
(handler.help = ["wastalk"]),
  (handler.tags = ["tools"]),
  (handler.command = /^(wa|whatsapp)stalk$/i);
export default handler;
