<?php
/* Central SEO configuration and rendering for Innovare Restoration. */

const SEO_BASE_URL = 'https://innovareremedial.com.au';
const SEO_SITE_NAME = 'Innovare Restoration';
const SEO_GSC_TOKEN = 'Khvn_ToOveCkIFVMz3tM0iYPg3PokzLqEpEa5Uxk6P4';
const SEO_GA_ID = 'G-5VTNRS7K4M';

function seo_pages()
{
    return [
        'home' => [
            'file' => 'index.html',
            'path' => '',
            'label' => 'Home',
            'title' => 'Innovare Remedial | Building & Remedial Repair Brisbane QLD',
            'description' => 'Expert flood restoration, mould remediation, concrete repair and heritage restoration across Brisbane and Gold Coast. Emergency response available. QBCC licensed.',
            'keywords' => 'Innovare remedial, remedial builders Brisbane, remedial builders Gold coast',
            'image' => 'images/innovare-restorations-img.webp',
        ],
        'about' => [
            'file' => 'about.html',
            'path' => 'about',
            'label' => 'About',
            'title' => 'About Innovare Remedial | Remedial Builders Brisbane',
            'description' => 'Meet the Innovare Remedial team — QBCC-licensed remedial builders with deep SEQ experience in flood, mould, structural and heritage restoration. Insurance-ready.',
            'image' => 'images/remedial-Specialist.webp',
        ],
        'services' => [
            'file' => 'services.html',
            'path' => 'services',
            'label' => 'Services',
            'title' => 'Our Services | Innovare Remedial Brisbane & Gold Coast',
            'description' => 'The full remedial spectrum — flood, mould, concrete, structural, heritage, roof, facade, fire, storm, defect, council order, asbestos, insurance and assessment services across Brisbane and SEQ.',
            'keywords' => 'remedial services Brisbane, restoration services Gold Coast, flood restoration, mould remediation, concrete repair, structural repair',
            'image' => 'images/Innovare-restorations.png',
        ],
        'projects' => [
            'file' => 'projects.html',
            'path' => 'projects',
            'label' => 'Projects',
            'title' => 'Projects Gallery | Innovare Remedial Brisbane',
            'description' => "Before and after project gallery — flood restoration, heritage repair, concrete repair and more across Brisbane and Gold Coast. View Innovare Remedial's work.",
            'keywords' => 'restoration projects Brisbane, remedial project gallery, flood restoration projects, heritage repair projects',
            'image' => 'images/Innovare-restorations.png',
        ],
        'blog' => [
            'file' => 'blog.html',
            'path' => 'blog',
            'label' => 'Blog',
            'title' => 'Building Restoration Blog | Innovare Remedial Brisbane',
            'description' => 'Expert articles on flood restoration, mould, concrete repair, heritage buildings and insurance works across Brisbane and SEQ. By the Innovare Remedial team.',
            'keywords' => 'building restoration blog, remedial construction articles, flood restoration advice, mould remediation advice',
            'image' => 'images/Innovare-restorations.png',
        ],
        'faq' => [
            'file' => 'faq.html',
            'path' => 'faq',
            'label' => 'FAQ',
            'title' => 'FAQ | Innovare Remedial Brisbane & Gold Coast',
            'description' => 'Frequently asked questions about flood restoration, mould remediation, insurance works, timelines and emergency response. Innovare Remedial Brisbane and Gold Coast.',
            'keywords' => 'Innovare Remedial FAQ, flood restoration questions, mould remediation questions, insurance repair questions',
            'image' => 'images/Innovare-restorations.png',
        ],
        'contact' => [
            'file' => 'contact.php',
            'path' => 'contact',
            'label' => 'Contact',
            'title' => 'Contact Innovare Remedial | Brisbane & Gold Coast',
            'description' => 'Contact Innovare Remedial for remedial building works, flood restoration, mould remediation and heritage restoration across Brisbane and Gold Coast. 24/7 emergency line.',
            'keywords' => 'contact Innovare Remedial, remedial builder Brisbane contact, flood restoration emergency Brisbane, building restoration quote',
            'image' => 'images/Innovare-restorations.png',
        ],
        'flood-restoration' => [
            'file' => 'flood-restoration.html',
            'path' => 'flood-restoration',
            'label' => 'Flood Restoration',
            'parent' => 'services',
            'title' => 'Flood Restoration Brisbane & Gold Coast | Innovare Remedial',
            'description' => '24/7 emergency flood restoration across Brisbane and Gold Coast. Water extraction, structural drying, mould prevention and full rebuild. QBCC licensed.',
            'keywords' => 'flood restoration Brisbane, water damage restoration Gold Coast, structural drying SEQ, emergency flood restoration, flood restoration Gold coast',
            'image' => 'images/flood-restoration.webp',
        ],
        'mould-remediation' => [
            'file' => 'mould-remediation.html',
            'path' => 'mould-remediation',
            'label' => 'Mould Remediation',
            'parent' => 'services',
            'title' => 'Mould Remediation Gold Coast & Brisbane | Innovare Remedial',
            'description' => 'Professional mould testing, containment, removal and prevention across Brisbane and Gold Coast. IICRC-aligned mould remediation. Safe, compliant, permanent.',
            'keywords' => 'mould remediation Brisbane, mould removal Gold Coast, mould testing SEQ, IICRC S520 mould remediation',
            'image' => 'images/mould-remediation.webp',
        ],
        'fire-damage-restoration' => [
            'file' => 'fire-damage-restoration.html',
            'path' => 'fire-damage-restoration',
            'label' => 'Fire Damage Restoration',
            'parent' => 'services',
            'title' => 'Fire Damage Restoration Brisbane | Emergency Response & Rebuild',
            'description' => 'Structural fire damage restoration across Brisbane and Gold Coast. Emergency make-safe, smoke remediation, structural assessment and full rebuild. QBCC licensed.',
            'keywords' => 'fire damage restoration Brisbane, smoke remediation Gold Coast, fire rebuild SEQ, emergency make-safe',
            'image' => 'images/fire-damage-restoration.webp',
        ],
        'storm-damage-restoration' => [
            'file' => 'storm-damage-restoration.html',
            'path' => 'storm-damage-restoration',
            'label' => 'Storm Damage Restoration',
            'parent' => 'services',
            'title' => 'Storm Damage Restoration Brisbane & Gold Coast | 24/7 Response',
            'description' => '24/7 storm and hail damage restoration across Brisbane and Gold Coast. Emergency make-safe, roof repairs, structural assessment and insurance support. QBCC licensed.',
            'keywords' => 'storm damage restoration Brisbane, hail damage repair Gold Coast, emergency storm make-safe, roof storm repairs',
            'image' => 'images/storm-damage-restoration.webp',
        ],
        'concrete-repair' => [
            'file' => 'concrete-repair.html',
            'path' => 'concrete-repair',
            'label' => 'Concrete Repair',
            'parent' => 'services',
            'title' => 'Concrete Repair Brisbane | Spalling, Cracking & Corrosion Repair',
            'description' => 'Specialist concrete repair in Brisbane and SEQ — spalling, cracking, carbonation and corrosion-damaged structures. QBCC licensed. Residential and commercial.',
            'keywords' => 'concrete repair Brisbane, concrete spalling repair, concrete cancer repair, corrosion repair SEQ',
            'image' => 'images/concrete-repair.webp',
        ],
        'structural-repair' => [
            'file' => 'structural-repair.html',
            'path' => 'structural-repair',
            'label' => 'Structural Repair',
            'parent' => 'services',
            'title' => 'Structural Repair Brisbane | Foundation & Load-Bearing Repairs',
            'description' => 'Expert structural repairs in Brisbane and Gold Coast — foundation repairs, load-bearing wall rectification, steel reinforcement and subsidence. QBCC licensed.',
            'keywords' => 'structural repair Brisbane, foundation repairs Gold Coast, load-bearing wall repair, steel reinforcement repair',
            'image' => 'images/structural-repair.webp',
        ],
        'building-defect-rectification' => [
            'file' => 'building-defect-rectification.html',
            'path' => 'building-defect-rectification',
            'label' => 'Building Defect Rectification',
            'parent' => 'services',
            'title' => 'Building Defect Rectification Brisbane | Innovare Remedial',
            'description' => 'Rectifying residential and commercial building defects across Brisbane and Gold Coast. QBCC licensed. Structural, waterproofing, cladding and finishing defects addressed.',
            'keywords' => 'building defect rectification Brisbane, waterproofing defects, cladding defects, commercial building defects',
            'image' => 'images/building-defect-rectification.webp',
        ],
        'roof-restoration' => [
            'file' => 'roof-restoration.html',
            'path' => 'roof-restoration',
            'label' => 'Roof Restoration',
            'parent' => 'services',
            'title' => 'Roof Restoration Brisbane & Gold Coast | Innovare Remedial',
            'description' => 'Professional roof restoration in Brisbane and Gold Coast — cleaning, repairs, recoating and waterproofing. QBCC licensed. Free assessment.',
            'keywords' => 'roof restoration Brisbane, roof repairs Gold Coast, roof recoating, roof waterproofing',
            'image' => 'images/roof-restoration.webp',
        ],
        'facade-restoration' => [
            'file' => 'facade-restoration.html',
            'path' => 'facade-restoration',
            'label' => 'Facade Restoration',
            'parent' => 'services',
            'title' => 'Facade Restoration Brisbane | Render, Cladding & External Repairs',
            'description' => 'Expert facade restoration across Brisbane and Gold Coast — render replacement, cladding repairs, facade waterproofing and external surface reinstatement. QBCC licensed.',
            'keywords' => 'facade restoration Brisbane, render repair Gold Coast, cladding repairs, facade waterproofing',
            'image' => 'images/facade-restoration.webp',
        ],
        'heritage-restoration' => [
            'file' => 'heritage-restoration.html',
            'path' => 'heritage-restoration',
            'label' => 'Heritage Restoration',
            'parent' => 'services',
            'title' => 'Heritage Restoration QLD |Innovare Remedial Brisbane',
            'description' => 'Expert heritage building restoration across Queensland — Burra Charter principles, period materials, council heritage approval support. QBCC licensed.',
            'keywords' => 'heritage restoration Queensland, heritage building repair Brisbane, Burra Charter restoration, period materials repair',
            'image' => 'images/heritage-restoration.webp',
        ],
        'asbestos-encapsulation' => [
            'file' => 'asbestos-encapsulation.html',
            'path' => 'asbestos-encapsulation',
            'label' => 'Asbestos Encapsulation',
            'parent' => 'services',
            'title' => 'Asbestos Encapsulation Brisbane | In-Situ Treatment QLD',
            'description' => 'Professional asbestos encapsulation services in Brisbane and Gold Coast — in-situ sealing where removal is not required. Licensed and compliant. QBCC licensed.',
            'keywords' => 'asbestos encapsulation Brisbane, in-situ asbestos sealing, asbestos treatment Gold Coast, compliant asbestos encapsulation',
            'image' => 'images/asbestos-encapsulation.webp',
        ],
        'council-order-rectification' => [
            'file' => 'council-order-rectification.html',
            'path' => 'council-order-rectification',
            'label' => 'Council Order Rectification',
            'parent' => 'services',
            'title' => 'Council Order Rectification Brisbane | Building Compliance Notices',
            'description' => 'Respond to council compliance orders and Show Cause notices in Brisbane and SEQ. QBCC-licensed builders. Clear scoping, fast response, compliant outcomes.',
            'keywords' => 'council order rectification Brisbane, building compliance notices, Show Cause notices SEQ, Direction to Rectify',
            'image' => 'images/council-order-rectification.webp',
        ],
        'insurance-repair-works' => [
            'file' => 'insurance-repair-works.html',
            'path' => 'insurance-repair-works',
            'label' => 'Insurance Repair Works',
            'parent' => 'services',
            'title' => 'Insurance Repair Works Brisbane | Innovare Remedial',
            'description' => 'Experienced insurance repair contractor for Brisbane and Gold Coast. Flood, fire, storm and defect claims. Scope documentation, insurer liaison and full repair delivery.',
            'keywords' => 'insurance repair works Brisbane, insurance builder Gold Coast, flood insurance repairs, storm insurance repairs',
            'image' => 'images/insurance-repair-works.webp',
        ],
        'remedial-consultation' => [
            'file' => 'remedial-consultation.html',
            'path' => 'remedial-consultation',
            'label' => 'Remedial Consultation',
            'parent' => 'services',
            'title' => 'Remedial Consultation Brisbane | Building Defect Assessment QLD',
            'description' => 'Expert building defect assessments and remedial consultation across Brisbane and Gold Coast. Documented reports, practical repair recommendations. QBCC licensed.',
            'keywords' => 'remedial consultation Brisbane, building defect assessment QLD, remedial report Gold Coast, building inspection SEQ',
            'image' => 'images/remediation-services.webp',
        ],
        'audit-and-priority-report' => [
            'file' => 'audit-and-priority-report.html',
            'path' => 'audit-and-priority-report',
            'label' => 'Audit & Priority Report',
            'parent' => 'services',
            'title' => 'Building Audit & Priority Report Brisbane | Innovare Remedial',
            'description' => 'Comprehensive building condition audits and prioritised remediation reports for Brisbane and Gold Coast properties. Expert assessment. QBCC licensed.',
            'keywords' => 'building audit Brisbane, priority report Gold Coast, building condition audit, remediation report SEQ',
            'image' => 'images/audit-and-priority-report.webp',
        ],
        '404' => [
            'file' => '404.html',
            'path' => '404.html',
            'label' => 'Page Not Found',
            'title' => 'Page Not Found | Innovare Remedial',
            'description' => 'The page you are looking for could not be found. Return to Innovare Remedial or contact the remedial building team.',
            'keywords' => '',
            'image' => 'images/Innovare-restorations.png',
            'robots' => 'noindex, nofollow',
            'sitemap' => false,
        ],
    ];
}

function seo_page($key)
{
    $pages = seo_pages();
    return isset($pages[$key]) ? $pages[$key] : $pages['home'];
}

function seo_url($path = '')
{
    $path = trim((string) $path, '/');
    return $path === '' ? SEO_BASE_URL . '/' : SEO_BASE_URL . '/' . $path;
}

function seo_asset_url($asset)
{
    return seo_url($asset);
}

function seo_sitemap_pages()
{
    return array_filter(seo_pages(), function ($page) {
        return !isset($page['sitemap']) || $page['sitemap'] !== false;
    });
}

function seo_escape($value)
{
    return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}

function seo_normalize_text($html)
{
    $html = preg_replace('/<br\s*\/?>/i', ' ', $html);
    $text = trim(html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8'));
    return preg_replace('/\s+/', ' ', $text);
}

function seo_extract_faq($file)
{
    if (!$file || !is_readable($file)) {
        return [];
    }

    $html = file_get_contents($file);
    if ($html === false || stripos($html, 'acc-q') === false) {
        return [];
    }

    preg_match_all('/<div class="acc-item">.*?<button class="acc-q">(.*?)<span class="acc-icon"><\/span><\/button>.*?<div class="acc-body-inner">(.*?)<\/div><\/div><\/div>/is', $html, $matches, PREG_SET_ORDER);

    $items = [];
    foreach ($matches as $match) {
        $question = seo_normalize_text($match[1]);
        $answer = seo_normalize_text($match[2]);
        if ($question !== '' && $answer !== '') {
            $items[] = [
                '@type' => 'Question',
                'name' => $question,
                'acceptedAnswer' => [
                    '@type' => 'Answer',
                    'text' => $answer,
                ],
            ];
        }
    }

    return $items;
}

function seo_breadcrumb_items($key, $page)
{
    $pages = seo_pages();
    $trail = [
        ['name' => 'Home', 'item' => seo_url('')],
    ];

    if (isset($page['parent'], $pages[$page['parent']])) {
        $parent = $pages[$page['parent']];
        $trail[] = [
            'name' => $parent['label'],
            'item' => seo_url($parent['path']),
        ];
    }

    if ($key !== 'home') {
        $trail[] = [
            'name' => $page['label'],
            'item' => seo_url($page['path']),
        ];
    }

    $items = [];
    foreach ($trail as $index => $item) {
        $items[] = [
            '@type' => 'ListItem',
            'position' => $index + 1,
            'name' => $item['name'],
            'item' => $item['item'],
        ];
    }

    return $items;
}

function seo_schema_graph($key, $page, $canonical)
{
    $graph = [
        [
            '@type' => 'Organization',
            '@id' => seo_url('#organization'),
            'name' => SEO_SITE_NAME,
            'url' => SEO_BASE_URL . '/',
            'logo' => seo_asset_url('images/Innovare-restorations.png'),
            'telephone' => '0488 773 232',
            'email' => 'info@innovarebuilders.com.au',
            'address' => [
                '@type' => 'PostalAddress',
                'streetAddress' => '29/97 Creek St',
                'addressLocality' => 'Brisbane City',
                'addressRegion' => 'QLD',
                'postalCode' => '4000',
                'addressCountry' => 'AU',
            ],
            'areaServed' => [
                ['@type' => 'Place', 'name' => 'Brisbane'],
                ['@type' => 'Place', 'name' => 'Gold Coast'],
                ['@type' => 'Place', 'name' => 'South East Queensland'],
            ],
            'parentOrganization' => [
                '@type' => 'Organization',
                'name' => 'Innovare Group',
            ],
            'identifier' => [
                ['@type' => 'PropertyValue', 'name' => 'QBCC Licence', 'value' => '15514239'],
                ['@type' => 'PropertyValue', 'name' => 'NSW Builder Licence', 'value' => '474965C'],
            ],
        ],
        [
            '@type' => 'BreadcrumbList',
            '@id' => $canonical . '#breadcrumb',
            'itemListElement' => seo_breadcrumb_items($key, $page),
        ],
    ];

    $faq = seo_extract_faq(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '');
    if ($faq) {
        $graph[] = [
            '@type' => 'FAQPage',
            '@id' => $canonical . '#faq',
            'mainEntity' => $faq,
        ];
    }

    return [
        '@context' => 'https://schema.org',
        '@graph' => $graph,
    ];
}

function render_seo_head($key)
{
    $page = seo_page($key);
    $canonical = seo_url($page['path']);
    $robots = isset($page['robots']) ? $page['robots'] : 'index, follow';
    $image = seo_asset_url(isset($page['image']) ? $page['image'] : 'images/Innovare-restorations.png');
    $ogType = $key === 'home' ? 'website' : 'website';
    ?>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?php echo seo_escape($page['title']); ?></title>
  <meta name="description" content="<?php echo seo_escape($page['description']); ?>">
<?php if (!empty($page['keywords'])) : ?>
  <meta name="keywords" content="<?php echo seo_escape($page['keywords']); ?>">
<?php endif; ?>
  <meta name="robots" content="<?php echo seo_escape($robots); ?>">
  <link rel="canonical" href="<?php echo seo_escape($canonical); ?>">
  <meta property="og:title" content="<?php echo seo_escape($page['title']); ?>">
  <meta property="og:description" content="<?php echo seo_escape($page['description']); ?>">
  <meta property="og:url" content="<?php echo seo_escape($canonical); ?>">
  <meta property="og:type" content="<?php echo seo_escape($ogType); ?>">
  <meta property="og:image" content="<?php echo seo_escape($image); ?>">
  <meta property="og:site_name" content="<?php echo seo_escape(SEO_SITE_NAME); ?>">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:title" content="<?php echo seo_escape($page['title']); ?>">
  <meta name="twitter:description" content="<?php echo seo_escape($page['description']); ?>">
  <meta name="twitter:image" content="<?php echo seo_escape($image); ?>">
  <link rel="icon" type="image/x-icon" href="images/favicon.png">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Archivo:wght@500;600;700;800&family=Hanken+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="assets/css/style.css">
<?php if ($key === 'home') : ?>
  <style>
    .svc-card > div {
    padding: 22px 14px 20px;
}
.svc-card {
    padding: 0px;
}
</style>
<?php endif; ?>
  <meta name="google-site-verification" content="<?php echo seo_escape(SEO_GSC_TOKEN); ?>" />
  <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo seo_escape(SEO_GA_ID); ?>"></script>
  <script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '<?php echo seo_escape(SEO_GA_ID); ?>');
  </script>
  <script type="application/ld+json"><?php echo json_encode(seo_schema_graph($key, $page, $canonical), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?></script>
<?php
}
