import React, { forwardRef } from "react"; import { BaseComponentProps } from "../../types"; export interface TermsSection { id: string; title: string; content: string | React.ReactNode; subsections?: TermsSection[]; } export interface TermsOfServiceProps extends BaseComponentProps { companyName?: string; contactEmail?: string; lastUpdated?: string; sections?: TermsSection[]; showTableOfContents?: boolean; enablePrint?: boolean; } const defaultSections: TermsSection[] = [ { id: "acceptance", title: "Acceptance of Terms", content: "By accessing and using our service, you accept and agree to be bound by the terms and provision of this agreement.", }, { id: "use-license", title: "Use License", content: "Permission is granted to temporarily use our service for personal, non-commercial transitory viewing only.", subsections: [ { id: "license-restrictions", title: "This license shall automatically terminate if you violate any of these restrictions", content: "You may not: modify or copy the materials; use the materials for any commercial purpose; attempt to reverse engineer any software; remove any copyright or proprietary notations.", }, ], }, { id: "disclaimer", title: "Disclaimer", content: "The materials on our service are provided on an 'as is' basis. We make no warranties, expressed or implied, and hereby disclaim all other warranties including, without limitation, implied warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement of intellectual property or other violation of rights.", }, { id: "limitations", title: "Limitations", content: "In no event shall our company or its suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption) arising out of the use or inability to use our service.", }, { id: "accuracy", title: "Accuracy of Materials", content: "The materials appearing on our service could include technical, typographical, or photographic errors. We do not warrant that any of the materials are accurate, complete, or current.", }, { id: "links", title: "Links", content: "We have not reviewed all of the sites linked to our service and are not responsible for the contents of any such linked site. The inclusion of any link does not imply endorsement by us of the site.", }, { id: "modifications", title: "Modifications", content: "We may revise these terms of service at any time without notice. By using this service, you are agreeing to be bound by the then current version of these terms of service.", }, { id: "governing-law", title: "Governing Law", content: "These terms and conditions are governed by and construed in accordance with the laws and you irrevocably submit to the exclusive jurisdiction of the courts in that state or location.", }, ]; export const TermsOfService = forwardRef( ( { className = "", companyName = "Your Company", contactEmail = "legal@yourcompany.com", lastUpdated = new Date().toISOString().split("T")[0], sections = defaultSections, showTableOfContents = true, enablePrint = true, ...props }, ref ) => { const handlePrint = () => { window.print(); }; const renderSection = (section: TermsSection, level = 1) => { const headingLevel = Math.min(level + 1, 6); return (
{headingLevel === 2 && (

{section.title}

)} {headingLevel === 3 && (

{section.title}

)} {headingLevel === 4 && (

{section.title}

)} {headingLevel === 5 && (
{section.title}
)} {headingLevel === 6 && (
{section.title}
)}
{typeof section.content === "string" ? (

{section.content}

) : ( section.content )}
{section.subsections && section.subsections.length > 0 && (
{section.subsections.map((subsection) => renderSection(subsection, level + 1) )}
)}
); }; const renderTableOfContents = () => { if (!showTableOfContents) return null; const renderTocItem = (section: TermsSection, level = 0) => (
  • 0 ? "ml-4" : ""}> {section.title} {section.subsections && section.subsections.length > 0 && ( )}
  • ); return (

    Table of Contents

    ); }; return (
    {/* Header */}

    Terms of Service

    {companyName}

    Last updated: {lastUpdated}

    {enablePrint && (
    )}
    {/* Table of Contents */} {renderTableOfContents()} {/* Content */}
    {sections.map((section) => renderSection(section))}
    {/* Footer */}

    Questions About These Terms?

    If you have any questions about these Terms of Service, please contact us at{" "} {contactEmail}

    ); } ); TermsOfService.displayName = "TermsOfService";