import { Head, usePage } from '@inertiajs/react';
import LegalDocument from '@/components/landing/legal-document';
import type { LegalSection } from '@/components/landing/legal-document';
import PublicPageHeader from '@/components/landing/public-page-header';

function termsSections(organisationName: string): LegalSection[] {
    return [
        {
            heading: 'About these terms',
            paragraphs: [
                `These terms govern your use of the ${organisationName} website, member dashboard and services. By creating an account you agree to them, together with our Privacy Policy.`,
            ],
        },
        {
            heading: 'Membership and eligibility',
            items: [
                'You must be at least 18 years old and resident in Nigeria.',
                'You must complete identity verification (BVN and a valid government-issued ID) before using savings or financing products.',
                'Information you provide must be accurate and kept up to date.',
                'Membership is subject to the cooperative’s bye-laws, which may require a share capital contribution, which is shown before you join.',
            ],
        },
        {
            heading: 'Your account and security',
            paragraphs: [
                'You are responsible for keeping your login details and 4-digit PIN confidential. Tell us immediately if you believe your account has been accessed without permission. We will never ask for your PIN by phone, SMS or email.',
            ],
        },
        {
            heading: 'Savings products',
            paragraphs: [
                'Savings plans are offered on clear, fair terms. Any returns on profit-sharing plans such as Mudarabah depend on actual performance and are not guaranteed. Each plan’s specific withdrawal rules and notice periods are shown before you subscribe.',
            ],
        },
        {
            heading: 'Financing products',
            paragraphs: [
                'Financing under Murabaha, Musharaka or Ijara is subject to approval and a separate financing agreement that sets out the asset, the agreed price or rental, and the repayment schedule. Any fees, and any charges for late repayment, are set out in your agreement before you accept.',
            ],
        },
        {
            heading: 'Acceptable use',
            items: [
                'Do not use our services for any unlawful purpose, including money laundering or fraud.',
                'Do not attempt to access other members’ accounts or interfere with our systems.',
                'Do not provide false or misleading information.',
            ],
        },
        {
            heading: 'Suspension and closure',
            paragraphs: [
                'We may suspend or close an account where we reasonably suspect fraud, a breach of these terms, or where required by law. You may close your account at any time, subject to settling any outstanding financing obligations.',
            ],
        },
        {
            heading: 'Liability',
            paragraphs: [
                'We take reasonable care to provide accurate information and a reliable service, but we are not liable for losses caused by events outside our reasonable control. Nothing in these terms limits liability that cannot be limited under Nigerian law.',
            ],
        },
        {
            heading: 'Governing law and disputes',
            paragraphs: [
                'These terms are governed by the laws of the Federal Republic of Nigeria. Please use our Complaints process first; unresolved disputes may be referred to the appropriate dispute resolution body or court in Nigeria.',
            ],
        },
    ];
}

export default function TermsOfUse() {
    const { name } = usePage().props;

    return (
        <>
            <Head title="Terms of Use" />

            <PublicPageHeader
                kicker="Legal"
                title="Terms of Use"
                intro={`The terms that apply when you join and use ${name}.`}
            />

            <LegalDocument sections={termsSections(name)} />
        </>
    );
}
