"use client";

import { useState } from "react";

export function ShareBar({ url, title }: { url: string; title: string }) {
  const [copied, setCopied] = useState(false);
  const encoded = encodeURIComponent(url);
  const text = encodeURIComponent(title);

  async function copy() {
    await navigator.clipboard.writeText(url);
    setCopied(true);
  }

  const item = "rounded-full border border-line px-3 py-1.5 text-xs text-navy transition hover:border-navy hover:bg-mist";

  return (
    <div className="flex flex-wrap items-center gap-2">
      <span className="text-xs tracking-wide text-muted">اشتراک‌گذاری</span>
      <a className={item} href={`https://www.linkedin.com/sharing/share-offsite/?url=${encoded}`} target="_blank" rel="noreferrer">لینکدین</a>
      <a className={item} href={`https://t.me/share/url?url=${encoded}&text=${text}`} target="_blank" rel="noreferrer">تلگرام</a>
      <button type="button" className={item} onClick={copy}>{copied ? "کپی شد" : "کپی پیوند"}</button>
    </div>
  );
}
