import { __ } from "@wordpress/i18n";
import CustomSection from "../components/CustomSection";
import WarmupCapability from "../components/WarmupCapability";
import CronDiagnostics from "../components/CronDiagnostics";

const CACHE_WARMUP_DOCS_URL = "https://wpcacheautopilot.com/docs/cache-warmup/";
const DIAGNOSTICS_PANEL_HELP_URLS = {
    warmupTransport: `${CACHE_WARMUP_DOCS_URL}#warmup-transport`,
    phpLimits: `${CACHE_WARMUP_DOCS_URL}#php-limits`,
    wpCron: `${CACHE_WARMUP_DOCS_URL}#wp-cron`,
};

const phpLimits = window.EkestoCacheWarmup?.phpLimits ?? {};

export default function DiagnosticsTab({ options, setOptions }) {
    return (
        <>
            <CustomSection
                title={__("Warmup Transport", "cache-autopilot")}
                helpUrl={DIAGNOSTICS_PANEL_HELP_URLS.warmupTransport}
            >
                <WarmupCapability options={options} setOptions={setOptions} />
            </CustomSection>

            <CustomSection
                title={__("PHP limits", "cache-autopilot")}
                helpUrl={DIAGNOSTICS_PANEL_HELP_URLS.phpLimits}
            >
                <>
                    <p className='ekesto-section-description'>
                        {__(
                            "This is your server’s configured maximum execution time:",
                            "cache-autopilot",
                        )}
                    </p>
                    <div className='ekesto-responsive-table-container'>
                        <div className='ekesto-responsive-table-inner'>
                            <table className='widefat striped ecw-diagnostics-table'>
                                <tbody>
                                    <tr>
                                        <th style={{ width: "260px" }}>
                                            {__("max_execution_time (s)", "cache-autopilot")}
                                        </th>
                                        <td>
                                            <code>
                                                {phpLimits.max_execution_time}
                                            </code>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </>
            </CustomSection>

            <CustomSection
                title={__("WP-Cron", "cache-autopilot")}
                helpUrl={DIAGNOSTICS_PANEL_HELP_URLS.wpCron}
            >
                <CronDiagnostics />
            </CustomSection>
        </>
    );
}
