import { useState } from 'react';
import { getLicenseStatus, activateLicense } from '@/lib/license';
import { runtimeConfig } from '@/lib/runtime-config';
export default function LicenseGate({children}){
  const [status,setStatus]=useState(()=>getLicenseStatus(runtimeConfig.mode));
  const [key,setKey]=useState(''); const [error,setError]=useState('');
  if(!runtimeConfig.requireLicense || status.active) return <>{children}</>;
  const activate=()=>{try{setStatus(activateLicense(key));setError('')}catch(e){setError(e.message)}};
  return <div className="min-h-screen bg-[#050b12] text-white flex items-center justify-center p-6"><div className="glass-panel max-w-lg p-8">
    <div className="text-xs uppercase tracking-[.3em] text-cyan-300">SHiRE Dental Studio</div><h1 className="mt-3 text-2xl font-semibold">Activate Professional Edition</h1>
    <p className="mt-3 text-sm text-slate-400">Enter a licence key or connect this installation to your future SHiRE licensing server. SHiRE OS module builds activate through the trusted SHiRE host automatically.</p>
    <input className="studio-input mt-6 w-full" value={key} onChange={e=>setKey(e.target.value)} placeholder="SHIRE-DENTAL-PRO-XXXXXXXX" />
    {error&&<p className="mt-2 text-sm text-rose-400">{error}</p>}
    <button className="primary-button mt-4 w-full" onClick={activate}>Activate licence</button>
    <p className="mt-4 text-[11px] text-slate-600">Commercial release must replace local development keys with server-verified signed licences and Stripe webhook validation.</p>
  </div></div>;
}
