import React, { useEffect, useState } from 'react';
import { __, sprintf } from '@wordpress/i18n';
import { useSettings } from '../useSettings';
import { api } from '../api';
import { Card, Button, Badge, Notice, Switch, Segmented, Field, PageState } from './ui';
/**
* GDPR / consent settings — the whole consent manager on one screen.
*
* Left: posture, layout, categories, texts. Right: a live mock of the banner
* that re-renders from the same values, so nobody has to open the front end
* in a private window to see what a wording change looks like.
*/
export default function ConsentPanel() {
const { data, s, update, save, busy, saved, error } = useSettings('/settings/analytics');
if (!data) return ;
const region = s.consent_region || 'eu';
return (
{}} />
{}} />
update({ consent_marketing: v })}
label={__('Marketing — show a category for ad and remarketing pixels you add via snippets', 'ai-rank-suite')}
/>
update({ consent_gcm: v })}
label={__('Google Consent Mode v2 — default denied under opt-in, updated live on choice, so GA4 keeps modelled data', 'ai-rank-suite')}
/>
update({ consent_reopen: v })}
label={__('Persistent reopen control (🍪 button in EU, “Do not sell or share” link in US)', 'ai-rank-suite')}
/>
{sprintf(__('US mode also prints a persistent “%s” link.', 'ai-rank-suite'), s.consent_dns || __('Do not sell or share my personal information', 'ai-rank-suite'))}
)}
);
}
/**
* Proof of consent.
*
* Article 7(1) puts the burden on the site to demonstrate that consent was
* given. A cookie in the visitor's browser demonstrates nothing — the site
* cannot produce it, and the visitor can clear it. This is the record the
* site can actually show, and the control that invalidates it when the
* policy text changes, because consent to one policy is not consent to a
* different one.
*
* Nothing here identifies anybody: the address and user agent are stored as
* salted hashes, enough to tell two decisions from one browser apart and
* useless for anything else.
*/
function ConsentRecord({ s, update, save }) {
const [log, setLog] = useState(null);
const [busy, setBusy] = useState('');
const [error, setError] = useState(null);
const load = () => api.get('/consent/log').then(setLog).catch((e) => setError(e.message));
useEffect(() => {
load();
}, []);
const run = async (name, fn) => {
setBusy(name);
setError(null);
try {
await fn();
} catch (e) {
setError(e.message);
} finally {
setBusy('');
}
};
const version = Number(s.consent_version || 1);
return (
{
update({ consent_log: v });
save({ consent_log: v });
}}
label={__('Keep a record', 'ai-rank-suite')}
/>
}
>
{error && {error}}
{s.consent_log === false ? (
{__('No record is kept. The banner still works and still gates the tags — but if anyone asks the site to demonstrate that a visitor agreed, there will be nothing to show.', 'ai-rank-suite')}
{__('Nothing recorded yet. The first visitor who answers the banner appears here — the record is written on their choice, not on their visit.', 'ai-rank-suite')}
{log.stale > 0 && (
{sprintf(__('%s of these were given under an older policy version. Those visitors are being asked again — their old answer no longer counts, which is the correct behaviour after the cookie policy changes.', 'ai-rank-suite'), log.stale.toLocaleString())}
)}
)}
{sprintf(__('Policy version %d', 'ai-rank-suite'), version)}
{__('Raise this after changing the cookie policy or adding a tag. Everyone who agreed to the old text is asked again; everyone else is left alone.', 'ai-rank-suite')}
{sprintf(__('Kept for %s days, then deleted automatically.', 'ai-rank-suite'), Number(s.consent_log_days || 365).toLocaleString())}