import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '../stores/authStore';
import SettingsLayout from '../components/layout/SettingsLayout';

function MyClinicPageContent() {
  const { dbUuid, fetchMe } = useAuthStore();
  const navigate = useNavigate();

  useEffect(() => {
    if (dbUuid) {
      navigate(`/admin/clinics/${dbUuid}`, { replace: true });
    } else {
      fetchMe().then(() => {
        const uuid = useAuthStore.getState().dbUuid;
        if (uuid) navigate(`/admin/clinics/${uuid}`, { replace: true });
      });
    }
  }, [dbUuid, fetchMe, navigate]);

  return (
    <div style={{ padding: 40, textAlign: 'center' }}>
      <p style={{ color: 'var(--text-3)', fontSize: 14 }}>در حال بارگذاری اطلاعات کلینیک...</p>
    </div>
  );
}

export default function MyClinicPage() {
  return (
    <SettingsLayout active="clinic">
      <MyClinicPageContent />
    </SettingsLayout>
  );
}
