import React, { useState, useEffect } from "react"; import { DBService } from "../lib/db"; import { WebsiteClone, BuiltSite } from "../types"; import { Cloud, RefreshCw, AlertTriangle, ShieldCheck, HelpCircle, Sparkles, FolderUp, CheckSquare, Zap, PlayCircle } from "lucide-react"; export default function DeployTab({ triggerHaptic }: { triggerHaptic: () => void }) { const [clones, setClones] = useState([]); const [selectedCloneId, setSelectedCloneId] = useState(""); const [targetPlatform, setTargetPlatform] = useState("Vercel"); const [deploying, setDeploying] = useState(false); const [deployStep, setDeployStep] = useState(0); const [deployedSiteUrl, setDeployedSiteUrl] = useState(""); // Free tiers usage status limit database const [limits, setLimits] = useState([ { platform: "Vercel Pages Build", used: 85, limit: 100, unit: "GB N-W", status: "critical" }, { platform: "Netlify Transfer Bandwidth", used: 42, limit: 100, unit: "GB Transfer", status: "good" }, { platform: "Render Free Database Run", used: 12, limit: 15, unit: "Projects", status: "warning" }, { platform: "Google Cloud Function Calls", used: 3.8, limit: 5, unit: "Million requests", status: "warning" }, { platform: "GitHub Actions Build min", used: 1240, limit: 2000, unit: "Minutes", status: "good" } ]); useEffect(() => { loadClones(); }, []); const loadClones = async () => { const list = await DBService.getAll("clones"); setClones(list); if (list.length > 0 && list[0]) { setSelectedCloneId(list[0].id); } }; const handleRunDeployment = async () => { if (!selectedCloneId) return; triggerHaptic(); setDeploying(true); setDeployStep(1); const matchClone = clones.find(c => c.id === selectedCloneId); if (!matchClone) return; // Simulated sequence of builds await new Promise(r => setTimeout(r, 1500)); setDeployStep(2); // Compiling assets await new Promise(r => setTimeout(r, 1200)); setDeployStep(3); // Connecting proxy webhook await new Promise(r => setTimeout(r, 1200)); // Finalize const urlSlug = matchClone.name.toLowerCase().replace(/\s+/g, "-"); const domain = targetPlatform === "Vercel" ? `${urlSlug}.vercel.app` : `${urlSlug}.netlify.app`; // Register as Built site in DB const built: BuiltSite = { id: "site_" + Date.now(), name: matchClone.name, url: `https://${domain}`, platform: targetPlatform, status: "live", deployUrl: targetPlatform === "Vercel" ? "https://vercel.com/dashboard" : "https://app.netlify.com", lastDeploy: Date.now(), analytics: { pageViews: 1, uptimePercentage: 100.0 } }; // Increment limits simulation setLimits(prev => prev.map(l => { if (l.platform.includes(targetPlatform)) { return { ...l, used: Math.min(l.limit, l.used + 2) }; } return l; })); await DBService.put("sites", built); await DBService.put("auditLog", { id: "log_" + Date.now(), timestamp: Date.now(), action: "دفع ونشر موقع تلقائياً", details: `تم نشر الكود المستنسخ لموقع [${matchClone.name}] بنجاح على منصة [${targetPlatform}]`, status: "success" }); setDeployedSiteUrl(domain); setDeployStep(4); setDeploying(false); }; return (
{/* 1. Quick Deploy Control (Left) */}

نشر كود مستنسخ بكبسة واحدة

{clones.length === 0 ? (
لا توجد سجلات مستنسخة بعد، يرجى الانتقال إلى علامة تبويب الاستنساخ وحصد موقع أولاً.
) : ( )}
{/* Quick deployment trigger */}
{/* Deploy steps presentation */} {deployStep > 0 && (

سجل عمليات النشر والربط

= 1 ? "bg-emerald-400" : "bg-slate-800"}`} /> تحصيل وتجهيز حزم الأكواد المفلترة
= 2 ? "bg-emerald-400" : "bg-slate-800"}`} /> تحجيم وضغط الملفات وتوريد CSS المجمَع
= 3 ? "bg-emerald-400" : "bg-slate-800"}`} /> دفع الأكواد لواجهة الـ API الخاصة بالنشر السريع
= 4 ? "bg-emerald-400 animate-pulse" : "bg-slate-800"}`} /> اكتمال النشر وربط النطاق مجاناً بنجاح!
{deployStep === 4 && deployedSiteUrl && (

تم تفعيل الرابط المباشر

https://{deployedSiteUrl}
)}
)}
{/* 2. Free Tier Limits Monitor (Right) */}

مراقب حدود السيرفرات المجانية (Resource Tracker)

يعمل هذا القسم على تتبع استهلاكك الشهري لمعالجة خوادم الاستضافة. يتم تصميمه لتوجيه استهلاكك وتلقي تنبيهات عند الاقتراب من الحدود القصوى.

{limits.map((l, index) => { const perc = Math.round((l.used / l.limit) * 100); const isHigh = perc >= 80; return (
{l.platform} {l.used} / {l.limit} {l.unit} ({perc}%)
{/* Progress Line */}
= 60 ? "bg-amber-400" : "bg-sky-400" }`} />
{/* Trigger warnings if alert logic is satisfied */} {isHigh && (
لقد استهلكت أكثر من 80% من الحصة المجانية! نوصي فوراً بجدولة ونشر استنساخاتك القادمة عبر منصة بديلة مثل Netlify أو Render لتجنب التوقف.
)}
); })}
); }