'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Info } from 'lucide-react';
import { ConfirmDangerousSettingDialog, SettingsCard, SettingsToggleRow } from './components.js';
export function SeoRobotsDefaultsCard({ form, setField, isProduction, indexStatus, canEdit, onNavigate, }) {
    const [pending, setPending] = useState(null);
    // Some toggles can take the whole production site out of search results, so
    // they route through a confirmation step before being applied.
    function requestToggle(field, value) {
        if (field === 'defaultNoIndex' && value && isProduction) {
            setPending({
                field,
                value,
                title: 'Block this production site from search engines?',
                description: 'This may prevent search engines from indexing your production site. Pages will be served with a noindex directive unless they explicitly opt in.',
                confirmLabel: 'Enable No Index',
            });
            return;
        }
        if (field === 'noIndexNonProduction' && !value) {
            setPending({
                field,
                value,
                title: 'Allow non-production environments to be indexed?',
                description: 'Preview and staging environments may become indexable if publicly accessible. Search engines could index unfinished content.',
                confirmLabel: 'Turn Off',
            });
            return;
        }
        setField(field, value);
    }
    const effectiveProd = form.defaultNoIndex ? 'Blocked' : 'Indexable';
    const sitemapCheck = indexStatus?.checks.find((c) => c.key === 'sitemap');
    const sitemapStatus = sitemapCheck ? (sitemapCheck.value === 'Yes' ? 'Enabled' : 'Disabled') : '—';
    return (_jsxs(SettingsCard, { title: "SEO & Robots Defaults", description: "Set the site-wide default for search engine indexing. Individual pages can inherit or override these rules in their SEO panel. These share the same configuration as the SEO section.", children: [_jsxs("div", { className: "space-y-4", children: [_jsx(SettingsToggleRow, { label: "Default No Index", description: "Ask search engines not to index pages unless a page explicitly allows indexing.", checked: form.defaultNoIndex, disabled: !canEdit, onChange: (v) => requestToggle('defaultNoIndex', v) }), _jsx(SettingsToggleRow, { label: "Default No Follow", description: "Ask search engines not to follow page links unless a page explicitly allows following.", checked: form.defaultNoFollow, disabled: !canEdit, onChange: (v) => requestToggle('defaultNoFollow', v) }), _jsx(SettingsToggleRow, { label: "Noindex Non-Production Environments", description: "Force noindex when the deployed environment is not production.", checked: form.noIndexNonProduction, disabled: !canEdit, onChange: (v) => requestToggle('noIndexNonProduction', v) }), isProduction && (_jsxs("p", { className: "text-muted-foreground flex items-start gap-2 text-sm", children: [_jsx(Info, { size: 16, className: "mt-0.5 shrink-0", "aria-hidden": "true" }), "This deployment is running in the production environment, so this setting does not change pages served here \u2014 it forces noindex only on preview, staging, and development deployments. To block search engines from this site, use Default No Index."] }))] }), _jsxs("div", { className: "border-border mt-4 space-y-2 border-t pt-4", children: [_jsx(SummaryRow, { label: "Effective production indexing", value: effectiveProd, danger: form.defaultNoIndex }), _jsx(SummaryRow, { label: "Effective current environment", value: indexStatus?.label ?? '—', danger: indexStatus?.severity === 'danger' }), _jsx(SummaryRow, { label: "Sitemap status", value: sitemapStatus }), onNavigate && (_jsx("button", { type: "button", onClick: () => onNavigate('/seo?tab=technical'), className: "text-brand mt-1 text-sm hover:underline", children: "Manage advanced robots.txt & sitemap in SEO \u2192" }))] }), _jsx(ConfirmDangerousSettingDialog, { open: pending !== null, title: pending?.title ?? '', description: pending?.description ?? '', confirmLabel: pending?.confirmLabel, onConfirm: () => {
                    if (pending)
                        setField(pending.field, pending.value);
                    setPending(null);
                }, onCancel: () => setPending(null) })] }));
}
function SummaryRow({ label, value, danger }) {
    return (_jsxs("div", { className: "flex items-center justify-between gap-2 text-sm", children: [_jsx("span", { className: "text-muted-foreground", children: label }), _jsx("span", { className: danger ? 'text-destructive font-medium' : 'text-foreground font-medium', children: value })] }));
}
//# sourceMappingURL=SeoRobotsDefaultsCard.js.map