<?php

declare(strict_types=1);

class DefaultPages
{
    public static function seed(): void
    {
        $siteName = Setting::get('site_name', 'My Site');
        $siteUrl = rtrim((string) Setting::get('site_url', 'https://example.com'), '/');

        $pages = self::getPages($siteName, $siteUrl);
        $today = date('F j, Y');

        foreach ($pages as $page) {
            $page['body'] = str_replace('{DATE}', $today, $page['body']);
            $existing = Database::fetchOne('SELECT id FROM pages WHERE slug = ?', [$page['slug']]);
            if ($existing) {
                continue;
            }
            Page::create($page);
        }
    }

    private static function getPages(string $name, string $url): array
    {
        $n = htmlspecialchars($name);
        $u = htmlspecialchars($url);

        return [
            [
                'title' => 'Contact',
                'slug' => 'contact',
                'body' => self::contactPage($n, $u),
                'meta_title' => "Contact Us",
                'meta_description' => "Get in touch with $name. Report copyright violations, content issues, or send us a general inquiry.",
                'status' => 'published',
                'sort_order' => 10,
                'show_in_footer' => 1,
                'has_contact_form' => 1,
            ],
            [
                'title' => 'Terms of Service',
                'slug' => 'terms',
                'body' => self::termsPage($n, $u),
                'meta_title' => "Terms of Service",
                'meta_description' => "Read the Terms of Service for $name. By accessing this website, you agree to be bound by these terms and conditions.",
                'status' => 'published',
                'sort_order' => 20,
                'show_in_footer' => 1,
            ],
            [
                'title' => 'DMCA',
                'slug' => 'dmca',
                'body' => self::dmcaPage($n, $u),
                'meta_title' => "DMCA Compliance Policy",
                'meta_description' => "DMCA compliance policy for $name. Learn how to file a copyright infringement notice or counter-notification.",
                'status' => 'published',
                'sort_order' => 30,
                'show_in_footer' => 1,
            ],
            [
                'title' => '18 U.S.C. 2257',
                'slug' => '2257',
                'body' => self::compliancePage($n, $u),
                'meta_title' => "18 U.S.C. 2257 Compliance Statement",
                'meta_description' => "18 U.S.C. 2257 record-keeping requirements compliance statement for $name. All performers are 18 years of age or older.",
                'status' => 'published',
                'sort_order' => 40,
                'show_in_footer' => 1,
            ],
            [
                'title' => 'Privacy Policy',
                'slug' => 'privacy',
                'body' => self::privacyPage($n, $u),
                'meta_title' => "Privacy Policy",
                'meta_description' => "Privacy Policy for $name. Learn how we collect, use, and protect your personal information.",
                'status' => 'published',
                'sort_order' => 50,
                'show_in_footer' => 1,
            ],
        ];
    }

    public static function contactPage(string $n, string $u): string
    {
        return <<<HTML
<div class="contact-page">
<p class="contact-intro">Need to reach us? Whether it's a <strong>DMCA takedown</strong>, a content or privacy concern, or a general question &mdash; send a message below. We read everything and reply within 24&ndash;48 hours, with legal matters handled first.</p>

<div class="contact-hub">
<div class="contact-hub__main">
<div class="contact-hub__main-title"><i class="fa-solid fa-paper-plane"></i> Send us a message</div>
<p class="contact-hub__main-sub">Choose a subject so your message reaches the right place. Fields marked <strong>*</strong> are required.</p>
[contact_form]
</div>
<div class="contact-hub__side">
<div class="cinfo">
<div class="cinfo__head"><span class="cinfo__icon"><i class="fa-solid fa-bolt"></i></span><span class="cinfo__title">Fast response</span></div>
<p class="cinfo__text">We aim to reply within <strong>24&ndash;48 hours</strong>. DMCA and legal requests are prioritized and usually answered within <strong>24 hours</strong>.</p>
</div>
<div class="cinfo">
<div class="cinfo__head"><span class="cinfo__icon"><i class="fa-solid fa-circle-check"></i></span><span class="cinfo__title">Before you write</span></div>
<ul class="cinfo__list">
<li><i class="fa-solid fa-check"></i> Your name and a reachable email</li>
<li><i class="fa-solid fa-check"></i> The right subject (DMCA, report, privacy&hellip;)</li>
<li><i class="fa-solid fa-check"></i> A clear, detailed description</li>
<li><i class="fa-solid fa-check"></i> For DMCA: the exact URL(s) and proof of ownership</li>
</ul>
</div>
<div class="cinfo">
<div class="cinfo__head"><span class="cinfo__icon"><i class="fa-solid fa-scale-balanced"></i></span><span class="cinfo__title">Policies &amp; reporting</span></div>
<p class="cinfo__text">Reporting something specific? Pick the matching subject in the form, or read the relevant policy:</p>
<div class="cinfo__links"><a href="{$u}/dmca">DMCA</a><a href="{$u}/2257">2257</a><a href="{$u}/privacy">Privacy</a><a href="{$u}/terms">Terms</a></div>
</div>
</div>
</div>

[last_updated]
</div>
HTML;
    }

    private static function termsPage(string $n, string $u): string
    {
        return <<<HTML
<h2>Terms of Service</h2>
[last_updated]

<h3>1. Acceptance of Terms</h3>
<p>By accessing and using {$n} ("{$u}"), you acknowledge that you have read, understood, and agree to be bound by these Terms of Service. If you do not agree with any part of these terms, you must not use this website. {$n} reserves the right to modify these terms at any time without prior notice. Your continued use of the website constitutes acceptance of any changes.</p>

<h3>2. Description of Service</h3>
<p>{$n} is a website that provides adult video content. All content is provided by third-party producers and content partners. {$n} does not produce primary content. All performers depicted on this website are 18 years of age or older at the time of filming. {$n} does not endorse or guarantee the accuracy of any third-party content or linked websites.</p>

<h3>3. Age Requirement</h3>
<p>To use this website, you affirm that you are at least <strong>eighteen (18) years of age</strong>, or the age of majority in your jurisdiction, whichever is greater. If you are under 18 years of age (or the applicable age of majority), you are strictly prohibited from accessing this website.</p>

<h3>4. User Conduct</h3>
<p>You agree not to:</p>
<ul>
<li>Use this website for any unlawful purpose or in violation of any applicable laws or regulations</li>
<li>Attempt to gain unauthorized access to any portion of this website, its servers, or any connected systems</li>
<li>Interfere with or disrupt the website's servers, networks, or infrastructure</li>
<li>Use any automated tools, bots, scrapers, or similar technology to access or collect data from this website</li>
<li>Copy, reproduce, distribute, or create derivative works from any content on this website without explicit written consent</li>
<li>Harass, abuse, or threaten other users or any person associated with {$n}</li>
<li>Upload, transmit, or distribute any content that is illegal, harmful, or violates the rights of others</li>
</ul>
<p>{$n} reserves the right to terminate access for any user who violates these terms, without prior notice, and to cooperate with law enforcement as necessary.</p>

<h3>5. Intellectual Property</h3>
<p>{$n} and its licensors own all intellectual property rights in the website, including but not limited to text, software, graphics, images, video, and audio content. Content is provided "AS IS" for personal, non-commercial use only. No reproduction, distribution, or modification is permitted without explicit written consent.</p>

<h3>6. Content Policy</h3>
<p>All performers featured on this website are verified to be 18 years of age or older. Content complies with 18 U.S.C. 2257 record-keeping requirements. {$n} responds promptly to valid DMCA takedown requests. We cooperate fully with law enforcement regarding any content concerns.</p>

<h3>7. Zero Tolerance Policy</h3>
<p>{$n} has a <strong>zero tolerance</strong> policy against child pornography, bestiality, rape, torture, snuff, death, and any other illegal material. Any content found to violate this policy will be removed immediately and reported to the appropriate authorities. We cooperate fully with law enforcement in investigating such content.</p>

<h3>8. Termination of Access</h3>
<p>{$n} may terminate or suspend your access to the website at any time, without prior notice, for any reason, including but not limited to violation of these Terms of Service, use of automated tools, or conduct that disrupts the operation of the website.</p>

<h3>9. Disclaimer of Warranties</h3>
<p>This website and its content are provided "AS IS" and "AS AVAILABLE" without warranties of any kind, either express or implied. {$n} does not warrant that the website will be uninterrupted, error-free, or free of viruses or other harmful components.</p>

<h3>10. Limitation of Liability</h3>
<p>In no event shall {$n}, its owners, operators, affiliates, or partners be liable for any indirect, incidental, special, consequential, or punitive damages arising out of or related to your use of this website.</p>

<h3>11. Indemnification</h3>
<p>You agree to indemnify, defend, and hold harmless {$n}, its owners, operators, affiliates, and partners from and against any claims, damages, obligations, losses, liabilities, costs, or expenses arising from your use of this website or violation of these Terms of Service.</p>

<h3>12. Governing Law</h3>
<p>These Terms of Service shall be governed by and construed in accordance with applicable laws. Any disputes arising from these terms or your use of this website shall be resolved through appropriate legal channels.</p>

<hr>
<p style="text-align:center;"><a href="{$u}/contact">Contact</a> · <a href="{$u}/dmca">DMCA</a> · <a href="{$u}/2257">2257</a> · <a href="{$u}/privacy">Privacy</a></p>
HTML;
    }

    private static function dmcaPage(string $n, string $u): string
    {
        return <<<HTML
<h2>DMCA Compliance Policy</h2>
<p><strong>Digital Millennium Copyright Act</strong></p>

<h3>DMCA Copyright Infringement Notice</h3>
<p>In accordance with the Digital Millennium Copyright Act of 1998 (the text of which may be found on the U.S. Copyright Office website at <a href="https://www.copyright.gov" target="_blank" rel="noopener noreferrer">https://www.copyright.gov</a>), {$n} will respond expeditiously to claims of copyright infringement that are reported to our designated copyright agent.</p>
<p>Please note that under Section 512(f) of the DMCA, any person who knowingly makes material misrepresentations that material or activity is infringing may be subject to liability for damages. {$n} reserves the right, at its sole discretion, to remove content which infringes or appears to infringe the intellectual or other rights of third parties.</p>

<h3>Filing a DMCA Complaint</h3>
<p>If you believe that your copyrighted work has been copied in a way that constitutes copyright infringement, please provide {$n}'s copyright agent with the following information:</p>
<ol>
<li>A physical or electronic signature of a person authorized to act on behalf of the owner of an exclusive right that is allegedly infringed.</li>
<li>Identification of the copyrighted work claimed to have been infringed, or, if multiple copyrighted works at a single online site are covered by a single notification, a representative list of such works at the Website.</li>
<li>Identification of the material that is claimed to be infringing or to be the subject of infringing activity and that is to be removed or access to which is to be disabled, and information reasonably sufficient to permit {$n} to locate the material (please provide direct URLs).</li>
<li>Information reasonably sufficient to permit {$n} to contact the complaining party, including a name, address, telephone number and, if available, an email address.</li>
<li>A statement that the complaining party has a good faith belief that use of the material in the manner complained of is not authorized by the copyright owner, its agent, or the law.</li>
<li>A statement that the information in the notification is accurate and, under penalty of perjury, that the complaining party is authorized to act on behalf of the owner of an exclusive right that is allegedly infringed.</li>
</ol>

<h3>Designated Copyright Agent</h3>
<p>All copyright infringement claims must be delivered to {$n}'s designated copyright agent. Please use our <a href="{$u}/contact">contact form</a> with the subject "DMCA Takedown Request".</p>

<h3>Counter-Notification</h3>
<p>If you believe that your content was removed or disabled by mistake or misidentification, you may file a counter-notification with us by providing the following information:</p>
<ul>
<li>Your physical or electronic signature</li>
<li>Identification of the material and its location before removal</li>
<li>A statement under penalty of perjury that the material was removed by mistake or misidentification</li>
<li>Your name, address, phone number, email, and a statement that you consent to federal court jurisdiction</li>
</ul>

<h3>Important Notice</h3>
<p>Please note that under Section 512(f) of the DMCA, any person who knowingly makes material misrepresentations that material or activity is infringing may be liable for damages. <strong>Do not make false claims.</strong></p>

<h3>Our Commitment</h3>
<p>{$n} respects the intellectual property rights of content producers, performers, and channels. We take copyright claims seriously and process valid DMCA requests promptly.</p>

<hr>
<p style="text-align:center;"><a href="{$u}/contact">Contact</a> · <a href="{$u}/terms">Terms</a> · <a href="{$u}/2257">2257</a> · <a href="{$u}/privacy">Privacy</a></p>
HTML;
    }

    private static function compliancePage(string $n, string $u): string
    {
        return <<<HTML
<h2>18 U.S.C. 2257 Compliance Statement</h2>
<p><strong>Record-Keeping Requirements Compliance Statement</strong></p>

<h3>Compliance Statement</h3>
<p>{$n} ("{$u}") is not a producer (primary or secondary) of any content found on this website. For content hosted on this website, the original producers of the content are responsible for maintaining records as required by 18 U.S.C. 2257 and 28 C.F.R. Part 75.</p>
<p>All performers depicted on this website were at least 18 years of age at the time of filming. Age verification documentation is maintained by the original producers of the content.</p>

<h3>Content Standards</h3>
<ul>
<li><strong>Visitor Age Requirement:</strong> All visitors must be 18 years or older to access this site. Adult content is strictly for adults only.</li>
<li><strong>Performer Age Verification:</strong> All content features performers who are 18 years of age or older. Content producers maintain age verification records as required by law.</li>
<li><strong>Content Compliance:</strong> We only host or aggregate content from producers who maintain proper 2257 compliance documentation.</li>
</ul>

<h3>Content Reporting</h3>
<p>{$n} takes all reports seriously. If you encounter any content that appears to violate our policies or applicable laws, please report it immediately.</p>
<p>Content that violates our policies or appears to involve underage performers will be <strong>removed immediately</strong> and reported to the appropriate authorities, including the National Center for Missing &amp; Exploited Children (NCMEC).</p>

<h3>Age Restriction Warning</h3>
<p>This website contains adult content. You must be at least 18 years old, or the age of majority in your jurisdiction, to access this site. By accessing this website, you acknowledge that you are of legal age and agree to our <a href="{$u}/terms">Terms of Service</a>.</p>

<h3>Our Commitment</h3>
<p>{$n} is committed to ensuring all content features adult performers only. We actively monitor our content, cooperate with authorities regarding any concerns, and maintain a zero-tolerance policy regarding any content that involves minors.</p>

<h3>Contact</h3>
<p>For questions about our content policy or to report concerns, please <a href="{$u}/contact">contact us</a>.</p>

<hr>
<p style="text-align:center;"><a href="{$u}/contact">Contact</a> · <a href="{$u}/terms">Terms</a> · <a href="{$u}/dmca">DMCA</a> · <a href="{$u}/privacy">Privacy</a></p>
HTML;
    }

    private static function privacyPage(string $n, string $u): string
    {
        return <<<HTML
<h2>Privacy Policy</h2>
[last_updated]

<h3>1. General</h3>
<p>This Privacy Policy describes how {$n} ("{$u}") collects, uses, and protects information when you visit our website. By using this website, you consent to the data practices described in this policy.</p>
<p>We reserve the right to revise, amend, or modify this Policy at any time. You should periodically review this page for changes. The date of last revision appears at the top of this Policy.</p>

<h3>2. Information We Collect</h3>
<p><strong>Passive Collection:</strong> We use cookies and similar technologies to collect non-personal information about your visit, including your IP address, browser type, referring pages, pages visited, and time spent on the site. This information is used to improve your browsing experience and analyze site traffic.</p>
<p><strong>Active Collection:</strong> We may collect personal information that you voluntarily provide, such as your name and email address when you use our contact form or create an account.</p>

<h3>3. How We Use Your Information</h3>
<p>We use the information we collect to:</p>
<ul>
<li>Provide and improve our services</li>
<li>Respond to your inquiries and requests</li>
<li>Analyze website usage and trends</li>
<li>Customize your experience on our website</li>
<li>Ensure the security of our website</li>
</ul>

<h3>4. Cookies</h3>
<p>This website uses cookies to improve your browsing experience. Cookies are small text files stored on your device that help us recognize your browser and remember certain information. You can configure your browser to refuse cookies, but some features of the website may not function properly.</p>

<h3>5. Disclosure of Information</h3>
<p>We may disclose personal information if we believe it is necessary to:</p>
<ul>
<li>Comply with applicable laws, regulations, or legal processes</li>
<li>Protect the rights, property, or safety of {$n}, our users, or the public</li>
<li>Enforce our Terms of Service</li>
<li>Respond to lawful requests from public authorities, including law enforcement</li>
</ul>

<h3>6. Data Security</h3>
<p>We implement industry-standard security measures, including SSL encryption, secure servers, and regular security audits, to protect the transmission and storage of information. However, no method of transmission over the Internet or electronic storage is 100% secure, and we cannot guarantee absolute security.</p>

<h3>7. Third-Party Links</h3>
<p>This website may contain links to third-party websites. We are not responsible for the privacy practices or content of these external sites. We encourage you to review the privacy policies of any third-party sites you visit.</p>

<h3>8. International Users</h3>
<p>For users in the European Union and other regions with data protection laws, we comply with applicable regulations regarding the collection and processing of personal data, including the General Data Protection Regulation (GDPR).</p>

<h3>9. Age Verification</h3>
<p>This website is intended for adults only. By using this site, you confirm that you are at least 18 years old or the age of majority in your jurisdiction.</p>

<h3>10. Your Rights</h3>
<p>Depending on your jurisdiction, you may have the right to:</p>
<ul>
<li>Access the personal data we hold about you</li>
<li>Request correction of inaccurate data</li>
<li>Request deletion of your personal data</li>
<li>Object to or restrict processing of your data</li>
</ul>
<p>To exercise any of these rights, please <a href="{$u}/contact">contact us</a>.</p>

<h3>11. Contact</h3>
<p>If you have any questions about this Privacy Policy, please <a href="{$u}/contact">contact us</a>.</p>

<hr>
<p style="text-align:center;"><a href="{$u}/contact">Contact</a> · <a href="{$u}/terms">Terms</a> · <a href="{$u}/dmca">DMCA</a> · <a href="{$u}/2257">2257</a></p>
HTML;
    }
}
