import React, { useEffect, useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { useSettings } from '../useSettings'; import { api } from '../api'; import { Card, Button, Switch, Badge, Notice, Tabs, Field, MediaPicker, TagInput, CheckGrid, CodeBlock, Gauge, PageState } from '../components/ui'; import Explain from '../components/Explain'; import LocalListings from '../components/LocalListings'; import { IconX, IconPin, IconMap, IconLayers, IconCode, IconSliders, IconLink, IconFile, IconChart, IconExternal } from '../components/icons'; const DAY_LABELS = { monday: __('Monday', 'ai-rank-suite'), tuesday: __('Tuesday', 'ai-rank-suite'), wednesday: __('Wednesday', 'ai-rank-suite'), thursday: __('Thursday', 'ai-rank-suite'), friday: __('Friday', 'ai-rank-suite'), saturday: __('Saturday', 'ai-rank-suite'), sunday: __('Sunday', 'ai-rank-suite'), }; const LANGUAGE_SUGGESTIONS = ['English', 'Deutsch', 'العربية', 'Français', 'Español', 'Italiano', 'Nederlands', 'Türkçe', 'Русский', '中文']; const TABS = [ { id: 'profile', label: __('Profile', 'ai-rank-suite') }, { id: 'hours', label: __('Hours', 'ai-rank-suite') }, { id: 'locations', label: __('Locations', 'ai-rank-suite') }, { id: 'reach', label: __('Reach & services', 'ai-rank-suite') }, { id: 'listings', label: __('Listings', 'ai-rank-suite') }, { id: 'output', label: __('Output', 'ai-rank-suite') }, ]; const TIER_LABEL = { required: __('Required', 'ai-rank-suite'), recommended: __('Recommended', 'ai-rank-suite'), optional: __('Nice to have', 'ai-rank-suite') }; const TIER_TONE = { required: 'red', recommended: 'yellow', optional: 'blue' }; /** A branch inherits every empty field from head office, so nothing is mandatory here. */ const BLANK_LOCATION = { name: '', business_type: '', street: '', street2: '', postal_code: '', city: '', region: '', country: '', phone: '', email: '', latitude: '', longitude: '', map_url: '', booking_url: '', price_range: '', image_url: '', own_hours: false, hours: {}, }; export default function LocalSeo() { const { data, s, update, save, run, busy, saved, error, setError, reload } = useSettings('/settings/local-seo'); // #/local-seo/listings opens that tab directly — the toolbar jump list and // the Insights sources strip link here by tab. const [tab, setTab] = useState(() => { const m = /#\/local-seo\/([a-z-]+)/.exec(window.location.hash || ''); return m && TABS.some((t) => t.id === m[1]) ? m[1] : 'profile'; }); const [preview, setPreview] = useState(null); const [geo, setGeo] = useState(null); const [openIndex, setOpenIndex] = useState(0); // The preview is the answer to "did my change land", so it reloads whenever // the page saves rather than only when the tab is first opened. useEffect(() => { if (tab !== 'output' || !data) return; api.get('/local-seo/preview').then(setPreview).catch(() => setPreview(null)); }, [tab, data]); if (!data) return ; const setHours = (day, patch) => update({ hours: { ...s.hours, [day]: { ...s.hours[day], ...patch } } }); const setLocation = (index, patch) => update({ locations: s.locations.map((l, i) => (i === index ? { ...l, ...patch } : l)) }); const setList = (key, index, patch) => update({ [key]: (s[key] || []).map((row, i) => (i === index ? { ...row, ...patch } : row)) }); const addTo = (key, blank) => update({ [key]: [...(s[key] || []), blank] }); const removeFrom = (key, index) => update({ [key]: (s[key] || []).filter((_, i) => i !== index) }); const findCoordinates = () => run(async () => { setGeo(null); const found = await api.post('/local-seo/geocode'); update({ latitude: found.latitude, longitude: found.longitude }); setGeo(found.matched || `${found.latitude}, ${found.longitude}`); }); const today = new Date().toISOString().slice(0, 10); const completeness = data.completeness || { score: 0, checks: [], required: 0 }; const missing = completeness.checks.filter((c) => !c.ok); const openNow = data.open_now || {}; return (
{error && {error}} } title={__('Local business', 'ai-rank-suite')} subtitle={__('One record, published as LocalBusiness schema and reused by every “near me” answer Google, ChatGPT and Perplexity give about you', 'ai-rank-suite')} action={
{saved && ✓ {__('Saved', 'ai-rank-suite')}} update({ enabled: v })} label={__('Publish', 'ai-rank-suite')} />
} >
{s.enabled ? ( {openNow.label} {openNow.until ? ` · ${openNow.until}` : ''} ) : ( {__('Not published — nothing is emitted yet', 'ai-rank-suite')} )} Site timezone: {data.timezone || 'UTC'}
{/* * What is left, as a task rather than a verdict. * * This was a column of red REQUIRED badges — every gap * listed at equal weight, which reads as a punishment * list and gives no idea how much work is actually left * or where to do it. A bar, a count, and one button that * opens the tab holding the next gap. */} {missing.length === 0 ? (

{__('Nothing left to fill in. The Output tab shows exactly what search engines and assistants will read.', 'ai-rank-suite')}

) : ( (() => { // Which tab each check belongs to, so the button can // send someone to the field rather than to the page. const TAB_OF = { hours: 'hours', areas: 'reach', services: 'reach', payment: 'reach', locations: 'locations', }; const tabFor = (c) => TAB_OF[c.id] || 'profile'; /* * Go to the field, not just to its tab. * * This only called setTab, and the field it is * about is usually on the profile tab, which is * the tab already open — so "Fill in street and * number" set the tab to the one you were on, * scrolled nowhere, and did nothing at all that * anybody could see. Reported, fairly, as a dead * button. * * The tab still has to change first for the * cases where the field is elsewhere, and the * scroll waits a frame so the new tab has * rendered before we look for the input. */ const goToField = (c) => { setTab(tabFor(c)); window.requestAnimationFrame(() => { const el = document.querySelector(`[data-airanksuite-field="${c.id}"]`); if (!el) return; el.scrollIntoView({ behavior: 'smooth', block: 'center' }); // Focus after the scroll, or the browser jumps twice. window.setTimeout(() => el.focus({ preventScroll: true }), 350); }); }; const req = missing.filter((c) => c.tier === 'required'); const rec = missing.filter((c) => c.tier === 'recommended'); const first = req[0] || rec[0] || missing[0]; const doneReq = (completeness.checks || []).filter((c) => c.tier === 'required' && c.ok).length; const totalReq = (completeness.checks || []).filter((c) => c.tier === 'required').length; return (
{req.length > 0 ? sprintf(_n('%1$d of %2$d required field filled in', '%1$d of %2$d required fields filled in', totalReq, 'ai-rank-suite'), doneReq, totalReq) : __('Every required field is filled in', 'ai-rank-suite')} {req.length > 0 && sprintf(__('%d required', 'ai-rank-suite'), req.length)} {req.length > 0 && rec.length > 0 && ' · '} {rec.length > 0 && sprintf(__('%d recommended', 'ai-rank-suite'), rec.length)}
{(completeness.checks || []) .filter((c) => c.tier === 'required') .map((c) => ( ))}
{sprintf(__('Next: %s', 'ai-rank-suite'), first.label)} {first.hint ? ` — ${first.hint}` : ''}
); })() )}
{tab === 'profile' && ( <> } title={__('Identity', 'ai-rank-suite')} subtitle={__('Who the business is, in the words an assistant will repeat', 'ai-rank-suite')}>
update({ name: e.target.value })} /> update({ legal_name: e.target.value })} /> update({ slogan: e.target.value })} />