����JFIF��`�`�����Viewing File: /home/u820193700/domains/spiti2026im.in/public_html/js/main_new.js
function App() {
  const [ready, setReady] = React.useState(false);

  React.useEffect(() => {
    const check = () => {
      if (window.Components && window.C && window.days) setReady(true);
      else setTimeout(check, 50);
    };
    check();
  }, []);

  const [view, setView] = React.useState(window.INITIAL_VIEW || "pub");
  const [data, setData] = React.useState({ regs: [], interests: [], qa: [], contacts: [], hotels: [], gallery: [] });
  const [adminUser, setAdminUser] = React.useState(null);
  const [adminTab, setAdminTab] = React.useState("overview");
  const [apiError, setApiError] = React.useState(null);

  const fetchData = async () => {
    try {
      setApiError(null);
      const res = await fetch((window.BASE_API || "api/") + "admin_actions.php?action=get_data").catch(e => { throw new Error("Network error or Blocked request: " + e.message); });
      if (res.ok) {
        const json = await res.json();
        if (json.regs) setData(json);
      } else {
        const text = await res.text();
        setApiError(`API Error ${res.status}: ${text.substring(0, 100)}`);
      }
    } catch (e) {
      console.error("Fetch error:", e);
      setApiError(e.message);
    }
  };

  React.useEffect(() => {
    if (view === "admin") fetchData();
  }, [view]);

  if (!ready) return <div style={{ height: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#888', fontSize: 14 }}>Initializing Spiti Expedition...</div>;

  const { PrayerFlags, MtnDiv, MtnDivFlip, Stars, DayCard, AdminLogin, AdminDashboard, DkF, DkSel } = window.Components;
  const { C, days: ALL_DAYS, exclusives: EXCLUSIVES, db, uid, fmtDate, cleanPhone } = window;


  const save = async (key, val, body = {}) => {
    const api = window.BASE_API || "api/";
    if (key === "regs" || key === "interests") {
      const res = await fetch(api + "register.php", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ ...body, type: key === "interests" ? "interest" : "full" }),
      });
      const json = await res.json().catch(() => ({}));
      if (res.ok) { 
        if (view === "admin") fetchData(); 
        return { success: true }; 
      }
      return { success: false, error: json.error || 'Submission failed. Please try again.' };
    } else if (key === "admin_update") {
      const res = await fetch(api + "admin_actions.php?action=" + body.action, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(body),
      });
      if (res.ok) fetchData();
    } else if (key === "contacts") {
      const res = await fetch(api + "admin_actions.php?action=add_contact", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(body),
      });
      if (res.ok) fetchData();
    } else if (key === "refresh") {
      fetchData();
    }
  };

  const onLogin = async (username, password) => {
    const res = await fetch((window.BASE_API || "api/") + "login.php", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ username, password }),
    });
    if (res.ok) {
      const json = await res.json();
      setAdminUser(json.admin);
      setView("admin");
      return true;
    }
    return false;
  };

  const renderContent = () => {
    if (!data)
      return (
        <div style={{ display: "flex", alignItems: "center", justifyContent: "center", height: "100vh", color: C.inkLight, fontSize: 16 }}>
          Loading Expedition Data...
        </div>
      );

    if (view === "login")
      return <AdminLogin onLogin={onLogin} onBack={() => setView("pub")} />;

    if (view === "admin") {
      return (
        <AdminDashboard
          data={data}
          save={save}
          tab={adminTab}
          setTab={setAdminTab}
          onLogout={() => setView("pub")}
        />
      );
    }

    return <PublicPage data={data} save={save} onAdmin={() => setView("login")} />;
  };

  return (
    <React.Fragment>
      {apiError && (
        <div style={{ position: 'fixed', top: 0, left: 0, right: 0, background: '#ef4444', color: 'white', padding: '10px 20px', zIndex: 10000, textAlign: 'center', fontSize: 13, fontWeight: 700 }}>
          ⚠️ API Connection Error: {apiError}. <button onClick={() => window.location.reload()} style={{ background: 'white', color: '#ef4444', border: 'none', padding: '2px 8px', borderRadius: 4, marginLeft: 10, cursor: 'pointer' }}>Retry</button>
        </div>
      )}
      {renderContent()}
    </React.Fragment>
  );
}
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����