'use client';

import { FaShareAlt } from 'react-icons/fa';
import { CustomToast } from '@/Utils/CustomToast';
import { getInfluencerJobUrl } from '@/Utils/Other/campaignShare';
import BorderButton from '@/Component/Common/Forms/BorderButton';

type Props = {
    slug: string;
    label?: string;
    customClass?: string;
};

const CopyCampaignLinkButton = ({ slug, label = 'Copy campaign link', customClass }: Props) => {
    const handleCopyLink = async () => {
        if (!slug) return;
        try {
            await navigator.clipboard.writeText(getInfluencerJobUrl(slug));
            CustomToast('info', 'Campaign link copied successfully');
        } catch {
            CustomToast('error', 'Unable to copy link');
        }
    };

    return (
        <BorderButton
            buttonType="button"
            title={label}
            customClass={`flex items-center gap-2 justify-center ${customClass || ''}`}
            onClick={handleCopyLink}
        >
            <FaShareAlt className="text-sm" />
            {label}
        </BorderButton>
    );
};

export default CopyCampaignLinkButton;
