import React from 'react';
import { useSearchParams } from 'react-router-dom';
import WoFeedbackForm from '../components/WoFeedbackForm';

const WoFeedbackPage: React.FC = () => {
  const [searchParams] = useSearchParams();
  const workOrder = (searchParams.get('work_order') || '').trim();
  const baseUrl = import.meta.env.BASE_URL || '/assets/asm_ui_app/';
  const logoUrl = `${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}seera-logo.png`;

  return (
    <div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-indigo-50 dark:from-gray-900 dark:via-gray-900 dark:to-indigo-950 flex flex-col items-center justify-center p-4">
      <div className="w-full max-w-md">
        <div className="flex justify-center mb-6">
          <img src={logoUrl} alt="Logo" className="h-10 object-contain" onError={e => { (e.target as HTMLImageElement).style.display = 'none'; }} />
        </div>

        <div className="bg-white dark:bg-gray-800 rounded-2xl shadow-xl border border-gray-200 dark:border-gray-700 p-6 md:p-8">
          {!workOrder ? (
            <div className="text-center py-6">
              <h1 className="text-lg font-bold text-gray-900 dark:text-white mb-2">Work Order Feedback</h1>
              <p className="text-sm text-gray-600 dark:text-gray-400">
                A work order link is required. Please use the link shared with you, for example:
              </p>
              <p className="mt-3 text-xs font-mono text-indigo-600 dark:text-indigo-400 break-all">
                /asm_app/wo-feedback?work_order=WO-00001
              </p>
            </div>
          ) : (
            <>
              <h1 className="text-lg font-bold text-gray-900 dark:text-white mb-1 text-center">
                Work Order Feedback
              </h1>
              {/* <p className="text-xs text-gray-500 dark:text-gray-400 text-center mb-6">
                No login required
              </p> */}
              <WoFeedbackForm workOrder={workOrder} />
            </>
          )}
        </div>
      </div>
    </div>
  );
};

export default WoFeedbackPage;
