feat: vista Orgánico con SEO (GA4/GSC) y GEO (visibilidad IA)

Nueva sección con métricas Search Console/GA4, cimientos SEO y
Share of Model por motor (ChatGPT/Gemini/AI Overviews).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-24 11:18:26 +02:00
parent dd0e867108
commit 5c90bcf940
8 changed files with 1529 additions and 1 deletions

View File

@@ -0,0 +1,885 @@
'use client';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import Link from 'next/link';
import {
Bot,
ExternalLink,
Loader2,
Plus,
Search,
Sparkles,
TrendingUp,
} from 'lucide-react';
import { PageHeader, SegmentedControl } from '@/components/ui';
import {
GEO_ENGINES,
SEO_FOUNDATIONS,
GeoSnapshot,
IntegrationLite,
OrganicDailyRow,
formatNum,
formatPct,
sumOrganic,
} from '@/lib/organic';
import { isoYesterday } from '@/lib/ad-tracker-range';
type Tab = 'seo' | 'geo';
type Props = {
label: string;
portfolioWide: boolean;
isAgency: boolean;
tenantId: string | null;
};
function connBadge(status?: string) {
if (status === 'connected')
return 'bg-emerald-50 text-emerald-800 border-emerald-200';
if (status === 'error') return 'bg-red-50 text-red-800 border-red-200';
if (status === 'pending') return 'bg-amber-50 text-amber-900 border-amber-200';
return 'bg-gray-50 text-gray-600 border-gray-200';
}
export default function OrganicoDashboard({
label,
portfolioWide,
isAgency,
tenantId,
}: Props) {
const [tab, setTab] = useState<Tab>('seo');
const [loading, setLoading] = useState(true);
const [warning, setWarning] = useState<string | null>(null);
const [organic, setOrganic] = useState<OrganicDailyRow[]>([]);
const [geo, setGeo] = useState<GeoSnapshot[]>([]);
const [integrations, setIntegrations] = useState<IntegrationLite[]>([]);
const [showGeoForm, setShowGeoForm] = useState(false);
const [saving, setSaving] = useState(false);
const [msg, setMsg] = useState<string | null>(null);
const [geoForm, setGeoForm] = useState({
label: 'Medición GEO',
share_of_model: '',
chatgpt: '',
gemini: '',
ai_overviews: '',
official_citation_pct: '',
sentiment_score: '',
prompts_analyzed: '',
responses_analyzed: '',
study_url: '',
notes: '',
competitors: 'Marca A, 40\nMarca B, 25\nTu marca, 12',
categories: 'General, 15\nCompra, 10\nComparativa, 8',
});
const [seoForm, setSeoForm] = useState({
day: isoYesterday(),
gsc_clicks: '',
gsc_impressions: '',
gsc_avg_position: '',
ga4_organic_sessions: '',
ga4_sessions: '',
ga4_users: '',
ga4_conversions: '',
});
const load = useCallback(async () => {
setLoading(true);
const res = await fetch('/api/organico');
const data = await res.json();
setOrganic(data.organic || []);
setGeo(data.geo || []);
setIntegrations(data.integrations || []);
setWarning(data.warning || null);
setLoading(false);
}, []);
useEffect(() => {
void load();
}, [load]);
const totals = useMemo(() => sumOrganic(organic), [organic]);
const latestGeo = geo[0] || null;
const byProvider = useMemo(() => {
const m = new Map<string, IntegrationLite>();
for (const i of integrations) m.set(i.provider, i);
return m;
}, [integrations]);
const ga4 = byProvider.get('ga4');
const gsc = byProvider.get('search_console');
async function saveOrganicDay() {
setSaving(true);
setMsg(null);
const res = await fetch('/api/organico', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
kind: 'organic',
...seoForm,
gsc_clicks: Number(seoForm.gsc_clicks) || 0,
gsc_impressions: Number(seoForm.gsc_impressions) || 0,
gsc_avg_position: seoForm.gsc_avg_position
? Number(seoForm.gsc_avg_position)
: null,
ga4_organic_sessions: Number(seoForm.ga4_organic_sessions) || 0,
ga4_sessions: Number(seoForm.ga4_sessions) || 0,
ga4_users: Number(seoForm.ga4_users) || 0,
ga4_conversions: Number(seoForm.ga4_conversions) || 0,
}),
});
const data = await res.json();
setSaving(false);
if (!res.ok) {
setMsg(data.error || 'Error');
return;
}
setMsg('Día SEO guardado');
await load();
}
function parsePairs(
raw: string
): { name: string; value: number }[] {
return raw
.split('\n')
.map((l) => l.trim())
.filter(Boolean)
.map((l) => {
const [name, num] = l.split(',').map((s) => s.trim());
return { name: name || '', value: Number(num) || 0 };
})
.filter((x) => x.name);
}
async function saveGeo() {
setSaving(true);
setMsg(null);
const comps = parsePairs(geoForm.competitors).map((x, i) => ({
brand: x.name!,
share: x.value,
rank: i + 1,
}));
const cats = parsePairs(geoForm.categories).map((x, i) => ({
category: x.name!,
visibility: x.value,
rank: i + 1,
}));
const res = await fetch('/api/organico', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
kind: 'geo',
label: geoForm.label,
share_of_model: geoForm.share_of_model
? Number(geoForm.share_of_model)
: null,
engines: {
chatgpt: geoForm.chatgpt ? Number(geoForm.chatgpt) : undefined,
gemini: geoForm.gemini ? Number(geoForm.gemini) : undefined,
ai_overviews: geoForm.ai_overviews
? Number(geoForm.ai_overviews)
: undefined,
},
official_citation_pct: geoForm.official_citation_pct
? Number(geoForm.official_citation_pct)
: null,
sentiment_score: geoForm.sentiment_score
? Number(geoForm.sentiment_score)
: null,
prompts_analyzed: geoForm.prompts_analyzed
? Number(geoForm.prompts_analyzed)
: null,
responses_analyzed: geoForm.responses_analyzed
? Number(geoForm.responses_analyzed)
: null,
study_url: geoForm.study_url || null,
notes: geoForm.notes || null,
competitors: comps,
categories: cats,
}),
});
const data = await res.json();
setSaving(false);
if (!res.ok) {
setMsg(data.error || 'Error');
return;
}
setMsg('Medición GEO registrada');
setShowGeoForm(false);
await load();
}
if (portfolioWide) {
return (
<div className="space-y-6">
<PageHeader
eyebrow="Crecimiento"
title="Orgánico"
description="SEO (GA4 + Search Console) y GEO (visibilidad en IA). Elige un cliente en Contexto."
/>
<p className="text-sm text-gray-600 border border-gray-200 rounded-xl px-4 py-8 text-center bg-gray-50">
Selecciona un cliente para ver su ficha orgánica.
</p>
</div>
);
}
if (loading) {
return (
<div className="flex items-center justify-center gap-2 py-20 text-sm text-gray-600">
<Loader2 className="w-4 h-4 animate-spin" /> Cargando orgánico…
</div>
);
}
return (
<div className="space-y-6">
<PageHeader
eyebrow="Crecimiento"
title="Orgánico"
description={`${label} · SEO clásico + GEO (recomendación en ChatGPT, Gemini y AI Overviews).`}
actions={
<SegmentedControl
value={tab}
onChange={setTab}
size="sm"
options={[
{ id: 'seo', label: 'SEO' },
{ id: 'geo', label: 'GEO · IA' },
]}
/>
}
/>
{warning && (
<p className="text-xs text-amber-900 border border-amber-300 bg-amber-50 rounded-lg px-3 py-2">
{warning}
</p>
)}
{msg && (
<p className="text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded-lg px-3 py-2">
{msg}
</p>
)}
{/* Connection strip */}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
{[
{ key: 'search_console', title: 'Search Console', row: gsc },
{ key: 'ga4', title: 'GA4', row: ga4 },
{
key: 'geo',
title: 'GEO / IA',
row: latestGeo
? { status: 'connected', external_account_id: latestGeo.label }
: { status: 'disconnected' },
},
].map((c) => (
<div
key={c.key}
className="rounded-xl border border-gray-200 bg-white px-4 py-3 shadow-sm"
>
<div className="flex items-center justify-between gap-2">
<p className="text-xs font-semibold text-gray-700">{c.title}</p>
<span
className={`text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full border ${connBadge(c.row?.status)}`}
>
{c.row?.status === 'connected' ? 'ON' : 'OFF'}
</span>
</div>
<p className="text-sm text-gray-900 mt-1 truncate font-medium">
{c.row?.external_account_id || 'Sin cuenta vinculada'}
</p>
{isAgency && tenantId && c.key !== 'geo' ? (
<Link
href={`/dashboard/agencia/cliente/${tenantId}`}
className="inline-flex items-center gap-1 text-[11px] font-semibold text-brand-700 mt-2 hover:underline"
>
Conectar en ficha <ExternalLink className="w-3 h-3" />
</Link>
) : null}
</div>
))}
</div>
{tab === 'seo' && (
<div className="space-y-6">
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3">
{[
{
label: 'Clics GSC',
value: formatNum(totals.gscClicks),
hint: 'Search Console',
},
{
label: 'Impresiones',
value: formatNum(totals.gscImpressions),
hint: 'Visibilidad SERP',
},
{
label: 'CTR medio',
value: formatPct(totals.gscCtr),
hint: 'Clics / impresiones',
},
{
label: 'Posición media',
value: totals.gscAvgPosition
? formatNum(totals.gscAvgPosition, 1)
: '—',
hint: 'Cuanto más bajo, mejor',
},
{
label: 'Sesiones orgánicas',
value: formatNum(totals.ga4Organic),
hint: 'GA4 · organic',
},
{
label: 'Usuarios',
value: formatNum(totals.ga4Users),
hint: 'GA4',
},
{
label: 'Sesiones totales',
value: formatNum(totals.ga4Sessions),
hint: 'GA4',
},
{
label: 'Conversiones',
value: formatNum(totals.ga4Conversions),
hint: 'GA4',
},
].map((k) => (
<div
key={k.label}
className="rounded-xl border border-gray-200 bg-white px-4 py-3 shadow-sm"
>
<p className="text-[11px] font-semibold uppercase tracking-wider text-gray-600">
{k.label}
</p>
<p className="text-xl font-bold text-gray-900 mt-1 tabular-nums">
{k.value}
</p>
<p className="text-[11px] text-gray-500 mt-0.5">{k.hint}</p>
</div>
))}
</div>
{!organic.length && (
<div className="rounded-xl border border-dashed border-gray-300 bg-gray-50 px-5 py-6">
<div className="flex items-start gap-3">
<Search className="w-5 h-5 text-brand-600 shrink-0 mt-0.5" />
<div>
<p className="text-sm font-semibold text-gray-900">
Sin serie SEO todavía
</p>
<p className="text-xs text-gray-600 mt-1 max-w-2xl leading-relaxed">
Como en el{' '}
<a
href="https://www.pixelclip.es/casos-de-exito/caso-de-exito-vivegreen"
target="_blank"
rel="noreferrer"
className="text-brand-700 font-semibold hover:underline"
>
caso Vivegreen
</a>
: primero cimientos técnicos, luego curva de clics e
impresiones. Conecta GSC/GA4 en la ficha; la agencia puede
cargar días manualmente hasta el sync automático.
</p>
</div>
</div>
</div>
)}
{organic.length > 0 && (
<section className="rounded-xl border border-gray-200 bg-white p-5 shadow-sm overflow-x-auto">
<h3 className="text-sm font-semibold text-gray-900 mb-3">
Serie diaria
</h3>
<table className="w-full text-left text-sm">
<thead className="text-gray-600 border-b border-gray-200">
<tr>
<th className="py-2 pr-3 font-semibold">Día</th>
<th className="py-2 pr-3 font-semibold">Clics</th>
<th className="py-2 pr-3 font-semibold">Impr.</th>
<th className="py-2 pr-3 font-semibold">CTR</th>
<th className="py-2 pr-3 font-semibold">Pos.</th>
<th className="py-2 pr-3 font-semibold">Org. GA4</th>
<th className="py-2 font-semibold">Conv.</th>
</tr>
</thead>
<tbody>
{[...organic].reverse().slice(0, 28).map((r) => {
const day = (r.day || r.date || '').slice(0, 10);
const clicks = Number(r.gsc_clicks) || 0;
const impr = Number(r.gsc_impressions) || 0;
const ctr =
r.gsc_ctr != null
? Number(r.gsc_ctr)
: impr > 0
? (100 * clicks) / impr
: 0;
return (
<tr
key={day}
className="border-b border-gray-100 hover:bg-gray-50"
>
<td className="py-2 pr-3 font-medium text-gray-900">
{day}
</td>
<td className="py-2 pr-3 tabular-nums">{formatNum(clicks)}</td>
<td className="py-2 pr-3 tabular-nums">{formatNum(impr)}</td>
<td className="py-2 pr-3 tabular-nums">{formatPct(ctr)}</td>
<td className="py-2 pr-3 tabular-nums">
{r.gsc_avg_position != null
? formatNum(Number(r.gsc_avg_position), 1)
: '—'}
</td>
<td className="py-2 pr-3 tabular-nums">
{formatNum(Number(r.ga4_organic_sessions) || 0)}
</td>
<td className="py-2 tabular-nums">
{formatNum(Number(r.ga4_conversions) || 0)}
</td>
</tr>
);
})}
</tbody>
</table>
</section>
)}
<section className="rounded-xl border border-gray-200 bg-white p-5 shadow-sm space-y-3">
<h3 className="text-sm font-semibold text-gray-900 flex items-center gap-2">
<TrendingUp className="w-4 h-4 text-brand-600" />
Cimientos SEO (seguimiento)
</h3>
<p className="text-xs text-gray-600">
Checklist inspirado en SEO técnico desde cero: indexación,
arquitectura y medición antes de escalar contenido.
</p>
<ul className="grid grid-cols-1 md:grid-cols-2 gap-2">
{SEO_FOUNDATIONS.map((f) => {
const ok =
f.id === 'medicion' &&
ga4?.status === 'connected' &&
gsc?.status === 'connected';
return (
<li
key={f.id}
className={`rounded-lg border px-3 py-2.5 ${
ok
? 'border-emerald-200 bg-emerald-50'
: 'border-gray-200 bg-gray-50'
}`}
>
<p className="text-sm font-semibold text-gray-900">
{f.title}
</p>
<p className="text-[11px] text-gray-600 mt-0.5">{f.hint}</p>
</li>
);
})}
</ul>
</section>
{isAgency && (
<section className="rounded-xl border border-brand-200 bg-brand-50/40 p-5 space-y-3">
<h3 className="text-sm font-semibold text-gray-900">
Cargar día (manual · hasta sync GA4/GSC)
</h3>
<div className="grid grid-cols-2 md:grid-cols-4 gap-2">
{(
[
['day', 'Día', 'date'],
['gsc_clicks', 'Clics GSC', 'number'],
['gsc_impressions', 'Impresiones', 'number'],
['gsc_avg_position', 'Posición media', 'number'],
['ga4_organic_sessions', 'Sesiones orgánicas', 'number'],
['ga4_sessions', 'Sesiones', 'number'],
['ga4_users', 'Usuarios', 'number'],
['ga4_conversions', 'Conversiones', 'number'],
] as const
).map(([key, lbl, type]) => (
<label key={key} className="block space-y-1">
<span className="text-[10px] font-semibold uppercase text-gray-600">
{lbl}
</span>
<input
type={type}
className="w-full rounded-lg border border-gray-200 bg-white px-2.5 py-1.5 text-sm"
value={seoForm[key]}
onChange={(e) =>
setSeoForm((s) => ({ ...s, [key]: e.target.value }))
}
/>
</label>
))}
</div>
<button
type="button"
disabled={saving}
onClick={() => void saveOrganicDay()}
className="inline-flex items-center gap-1.5 text-sm font-semibold px-4 py-2 rounded-lg bg-brand-500 text-white hover:bg-brand-600 disabled:opacity-50"
>
{saving ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Plus className="w-4 h-4" />
)}
Guardar día
</button>
</section>
)}
</div>
)}
{tab === 'geo' && (
<div className="space-y-6">
<div className="rounded-xl border border-gray-200 bg-white p-5 shadow-sm space-y-2">
<div className="flex items-start gap-3">
<Bot className="w-5 h-5 text-brand-600 shrink-0 mt-0.5" />
<div>
<p className="text-sm font-semibold text-gray-900">
Visibilidad en IA (GEO)
</p>
<p className="text-xs text-gray-600 mt-1 max-w-3xl leading-relaxed">
Framework alineado con estudios tipo{' '}
<a
href="https://www.pixelclip.es/casos-de-exito/benchmark-de-visibilidad-en-ia-protectores-solares-en-espana-2026"
target="_blank"
rel="noreferrer"
className="text-brand-700 font-semibold hover:underline"
>
Pixelclip · Share of Model
</a>
: qué marca recomienda ChatGPT / Gemini / AI Overviews, cuota
de citas a web oficial y ranking por intención.
</p>
</div>
</div>
</div>
{latestGeo ? (
<>
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3">
{[
{
label: 'Share of Model',
value:
latestGeo.share_of_model != null
? formatPct(Number(latestGeo.share_of_model))
: '—',
hint: '% menciones / 1ª respuesta',
},
{
label: 'Citas web oficial',
value:
latestGeo.official_citation_pct != null
? formatPct(Number(latestGeo.official_citation_pct))
: '—',
hint: 'Fuentes → dominio marca',
},
{
label: 'Sentimiento',
value:
latestGeo.sentiment_score != null
? formatNum(Number(latestGeo.sentiment_score), 0)
: '—',
hint: '0–100',
},
{
label: 'Muestra',
value:
latestGeo.prompts_analyzed != null
? formatNum(Number(latestGeo.prompts_analyzed))
: '—',
hint:
latestGeo.responses_analyzed != null
? `${formatNum(Number(latestGeo.responses_analyzed))} respuestas`
: 'Prompts analizados',
},
].map((k) => (
<div
key={k.label}
className="rounded-xl border border-brand-200 bg-brand-50 px-4 py-3 shadow-sm"
>
<p className="text-[11px] font-semibold uppercase tracking-wider text-brand-700">
{k.label}
</p>
<p className="text-xl font-bold text-gray-900 mt-1 tabular-nums">
{k.value}
</p>
<p className="text-[11px] text-gray-600 mt-0.5">{k.hint}</p>
</div>
))}
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-3">
{GEO_ENGINES.map((eng) => {
const v = Number(
(latestGeo.engines || {})[
eng.id as keyof typeof latestGeo.engines
] ?? NaN
);
return (
<div
key={eng.id}
className="rounded-xl border border-gray-200 bg-white px-4 py-4 shadow-sm"
>
<p className="text-xs font-semibold text-gray-600">
{eng.label}
</p>
<p className="text-2xl font-bold text-gray-900 mt-1 tabular-nums">
{Number.isFinite(v) ? formatPct(v) : '—'}
</p>
<div className="mt-3 h-2 rounded-full bg-gray-100 overflow-hidden">
<div
className="h-full bg-brand-500 rounded-full"
style={{
width: `${Number.isFinite(v) ? Math.min(100, v) : 0}%`,
}}
/>
</div>
</div>
);
})}
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
<section className="rounded-xl border border-gray-200 bg-white p-5 shadow-sm">
<h3 className="text-sm font-semibold text-gray-900 mb-3">
Ranking Share of Model
</h3>
{(latestGeo.competitors || []).length === 0 ? (
<p className="text-xs text-gray-500">Sin competidores.</p>
) : (
<ul className="space-y-2">
{(latestGeo.competitors || []).map((c, i) => (
<li
key={`${c.brand}-${i}`}
className="flex items-center gap-3"
>
<span className="text-xs font-bold text-gray-500 w-5">
{c.rank || i + 1}
</span>
<div className="flex-1 min-w-0">
<div className="flex justify-between gap-2 text-sm">
<span className="font-semibold text-gray-900 truncate">
{c.brand}
</span>
<span className="tabular-nums text-gray-700 font-medium">
{formatPct(Number(c.share))}
</span>
</div>
<div className="mt-1 h-1.5 rounded-full bg-gray-100 overflow-hidden">
<div
className="h-full bg-brand-500"
style={{
width: `${Math.min(100, Number(c.share) || 0)}%`,
}}
/>
</div>
</div>
</li>
))}
</ul>
)}
</section>
<section className="rounded-xl border border-gray-200 bg-white p-5 shadow-sm">
<h3 className="text-sm font-semibold text-gray-900 mb-3">
Por intención / categoría
</h3>
{(latestGeo.categories || []).length === 0 ? (
<p className="text-xs text-gray-500">Sin categorías.</p>
) : (
<ul className="space-y-2">
{(latestGeo.categories || []).map((c, i) => (
<li
key={`${c.category}-${i}`}
className="flex items-center justify-between gap-3 text-sm border-b border-gray-100 pb-2"
>
<span className="font-medium text-gray-900">
{c.category}
</span>
<span className="tabular-nums font-semibold text-brand-700">
{formatPct(Number(c.visibility))}
</span>
</li>
))}
</ul>
)}
</section>
</div>
{latestGeo.notes || latestGeo.study_url ? (
<p className="text-xs text-gray-600">
{latestGeo.notes}{' '}
{latestGeo.study_url ? (
<a
href={latestGeo.study_url}
target="_blank"
rel="noreferrer"
className="text-brand-700 font-semibold hover:underline"
>
Ver estudio
</a>
) : null}
</p>
) : null}
{geo.length > 1 && (
<p className="text-[11px] text-gray-500">
Historial: {geo.length} mediciones · última{' '}
{latestGeo.created_at
? new Date(latestGeo.created_at).toLocaleDateString('es-ES')
: ''}
</p>
)}
</>
) : (
<div className="rounded-xl border border-dashed border-gray-300 bg-gray-50 px-5 py-8 text-center space-y-2">
<Sparkles className="w-6 h-6 text-brand-600 mx-auto" />
<p className="text-sm font-semibold text-gray-900">
Aún no hay medición GEO
</p>
<p className="text-xs text-gray-600 max-w-lg mx-auto">
Registra Share of Model, motores (ChatGPT / Gemini / AI
Overviews) y ranking competitivo cuando tengas un estudio o
muestra de prompts.
</p>
</div>
)}
{isAgency && (
<div className="space-y-3">
<button
type="button"
onClick={() => setShowGeoForm((v) => !v)}
className="inline-flex items-center gap-1.5 text-sm font-semibold px-4 py-2 rounded-lg bg-brand-500 text-white hover:bg-brand-600"
>
<Plus className="w-4 h-4" />
{showGeoForm ? 'Cerrar formulario' : 'Nueva medición GEO'}
</button>
{showGeoForm && (
<section className="rounded-xl border border-brand-200 bg-white p-5 space-y-3 shadow-sm">
<div className="grid grid-cols-2 md:grid-cols-4 gap-2">
<label className="block space-y-1 col-span-2">
<span className="text-[10px] font-semibold uppercase text-gray-600">
Etiqueta
</span>
<input
className="w-full rounded-lg border border-gray-200 px-2.5 py-1.5 text-sm"
value={geoForm.label}
onChange={(e) =>
setGeoForm((s) => ({ ...s, label: e.target.value }))
}
/>
</label>
{(
[
['share_of_model', 'Share of Model %'],
['official_citation_pct', 'Citas oficial %'],
['sentiment_score', 'Sentimiento 0–100'],
['chatgpt', 'ChatGPT %'],
['gemini', 'Gemini %'],
['ai_overviews', 'AI Overviews %'],
['prompts_analyzed', 'Prompts'],
['responses_analyzed', 'Respuestas'],
] as const
).map(([key, lbl]) => (
<label key={key} className="block space-y-1">
<span className="text-[10px] font-semibold uppercase text-gray-600">
{lbl}
</span>
<input
type="number"
className="w-full rounded-lg border border-gray-200 px-2.5 py-1.5 text-sm"
value={geoForm[key]}
onChange={(e) =>
setGeoForm((s) => ({ ...s, [key]: e.target.value }))
}
/>
</label>
))}
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
<label className="block space-y-1">
<span className="text-[10px] font-semibold uppercase text-gray-600">
Competidores (marca, share%)
</span>
<textarea
className="w-full rounded-lg border border-gray-200 px-2.5 py-1.5 text-sm min-h-[88px] font-mono"
value={geoForm.competitors}
onChange={(e) =>
setGeoForm((s) => ({
...s,
competitors: e.target.value,
}))
}
/>
</label>
<label className="block space-y-1">
<span className="text-[10px] font-semibold uppercase text-gray-600">
Categorías (nombre, visibilidad%)
</span>
<textarea
className="w-full rounded-lg border border-gray-200 px-2.5 py-1.5 text-sm min-h-[88px] font-mono"
value={geoForm.categories}
onChange={(e) =>
setGeoForm((s) => ({
...s,
categories: e.target.value,
}))
}
/>
</label>
</div>
<label className="block space-y-1">
<span className="text-[10px] font-semibold uppercase text-gray-600">
URL estudio / notas
</span>
<input
className="w-full rounded-lg border border-gray-200 px-2.5 py-1.5 text-sm"
placeholder="https://…"
value={geoForm.study_url}
onChange={(e) =>
setGeoForm((s) => ({ ...s, study_url: e.target.value }))
}
/>
<textarea
className="w-full rounded-lg border border-gray-200 px-2.5 py-1.5 text-sm mt-2"
placeholder="Notas internas"
value={geoForm.notes}
onChange={(e) =>
setGeoForm((s) => ({ ...s, notes: e.target.value }))
}
/>
</label>
<button
type="button"
disabled={saving}
onClick={() => void saveGeo()}
className="inline-flex items-center gap-1.5 text-sm font-semibold px-4 py-2 rounded-lg bg-brand-500 text-white hover:bg-brand-600 disabled:opacity-50"
>
{saving ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Sparkles className="w-4 h-4" />
)}
Guardar medición GEO
</button>
</section>
)}
</div>
)}
</div>
)}
</div>
);
}