import { clearAllCaches } from '@/utils/commons';
import { BUILD_VERSION, BUILD_DATE } from '@/config'

const MaintenancePage = () => {
  const handleClearCache = async () => {
    await clearAllCaches(alert(`清除成功🎉`));
  };

  const handleReload = () => {
    const url = new URL(window.location.href);
    url.searchParams.forEach((value, name) => {
      url.searchParams.delete(name);
    });
    const _num = Date.now();
    url.searchParams.set('_spam' + _num, _num);
    window.location.href = url.toString();
  };

  const handleVersionCheck = () => {};
  const toHome = () => {
    window.location.href = '/';
  };

  return (
    <>
      <div className='flex flex-col items-center justify-center h-5/6 bg-gray-100'>
        <h1 className='text-2xl font-bold mb-4 text-slate-800'>Sales CRM Maintenance Page</h1>
        <button onClick={handleClearCache} className='px-4 py-2 mb-4 bg-blue-500 text-white rounded-md border-0'>
          清除缓存
        </button>
        <button onClick={handleReload} className='px-4 py-2 mb-4 bg-green-500 text-white rounded-md border-0'>
          检查版本
        </button>
        {/* <button onClick={handleVersionCheck} className='px-4 py-2 mb-2 bg-yellow-500 text-white rounded-md border-0'>
          检查版本
        </button> */}
        <button onClick={toHome} className='px-4 py-2 mb-2 bg-red-400 text-white rounded-md border-0'>
          打开系统
        </button>
        <p>Version: {BUILD_VERSION}</p>
        <p>Build Date: {BUILD_DATE}</p>
      </div>
    </>
  );
};
export default MaintenancePage;
