import type { JobPosting } from '@/types/entities'; import React, { useState, useMemo } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import { Copy, Check, Share2, Mail, Link2, Smartphone, Users } from 'lucide-react'; import { toast } from 'react-hot-toast'; interface InviteApplicantsModalProps { open: boolean; onClose?: () => void; job: JobPosting; } export default function InviteApplicantsModal({ open, onClose, job }: InviteApplicantsModalProps) { const [copied, setCopied] = useState(false); const [emailRecipients, setEmailRecipients] = useState(''); const [sending, setSending] = useState(false); const shareUrl = useMemo(() => { if (!job?.id) return ''; const base = window.location.origin; return `${base}/apply?job=${job.id}`; }, [job?.id]); const jobTitle = job?.title || 'this position'; const handleCopyLink = async () => { try { await navigator.clipboard.writeText(shareUrl); setCopied(true); toast.success('Invitation link copied!'); setTimeout(() => setCopied(false), 2000); } catch { toast.error('Could not copy link'); } }; const handleNativeShare = async () => { if (navigator.share) { try { await navigator.share({ title: `Apply: ${jobTitle} at KROW`, text: `You've been invited to apply for ${jobTitle}. Complete a quick 5-minute AI interview — no forms, no quizzes.`, url: shareUrl, }); } catch { /* user cancelled */ } } else { handleCopyLink(); } }; const handleEmailInvite = () => { const recipients = emailRecipients.trim(); if (!recipients) return; const subject = `You're invited to apply: ${jobTitle}`; const body = `Hi,\n\nYou've been invited to apply for ${jobTitle} at KROW.\n\nClick the link below to view the position and complete a quick 5-minute AI interview:\n\n${shareUrl}\n\nNo long forms, no quizzes — just speak naturally and get instant feedback.\n\nKROW Talent Engine`; const mailtoUrl = `mailto:${recipients}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; window.location.href = mailtoUrl; setSending(true); setTimeout(() => { setSending(false); toast.success('Email invitation opened'); }, 500); }; return ( !v && onClose()}> Invite Applicants
{/* Job info */}

{jobTitle}

{job?.location &&

{job.location}

} {job?.pay_range_min != null && (

${job.pay_range_min}–${job.pay_range_max}/hr

)}
{/* Shareable Link */}
{/* Native Share (mobile) */} {/* Email Invite */}