import { ReactElement, Suspense, useContext, useState } from 'react';
import {
  Button,
  FormControl,
  IconButton,
  InputAdornment,
  InputLabel,
  Link,
  Skeleton,
  Stack,
  TextField,
  Typography,
} from '@mui/material';

import { useNavigate } from 'react-router-dom';
import { axiosInstance } from '../../axiosApi';
import { AccountContext } from 'contexts/AccountContext';
import { AxiosResponse } from 'axios';
import { UserAPI } from 'types';

const TermsOfService = (): ReactElement => {
  const [errors, setErrors] = useState<string | null>(null);
  const navigate = useNavigate();
  const { account, setAccount, accountLoading } = useContext(AccountContext);

  const handleSignTOS = async (): Promise<void> => {
    console.log('handle tos signing');
    try {
      const { data }: AxiosResponse<UserAPI> = await axiosInstance.put('/user/acknowledge_tos/');
      if (data) {
        setAccount(data);
      }

      navigate('/');
    } catch (error) {
      setErrors(error);
    }
  };

  return (
    <Stack
      direction="row"
      bgcolor="background.paper"
      boxShadow={(theme) => theme.shadows[3]}
      minHeight={560}
      width={{ md: 960 }}
    >
      <Stack m={2.5} gap={10}>
        <Stack alignItems="center" gap={2.5} mx="auto">
          <Typography variant="h1">Terms Of Service</Typography>

          <FormControl variant="standard" fullWidth>
            <Typography variant="caption">Last Updated: July 15, 2025</Typography>
            <Typography variant="body1">
              Welcome to [Your Website Name]! These Terms of Service ("Terms") govern your access to
              and use of the [Your Website Name] website portal (the "Service"), operated by [Your
              Company Name] ("we," "us," or "our").
            </Typography>
            <Typography variant="body1">
              By accessing or using the Service, you agree to be bound by these Terms and our
              Privacy Policy. If you do not agree to these Terms, please do not use the Service.
            </Typography>
            <Typography>
              <Typography variant="h4">1. Acceptance of Terms</Typography>
              <Typography variant="body1">
                By creating an account, accessing, or using the Service, you signify your agreement
                to these Terms. You must be at least 18 years old or the age of legal majority in
                your jurisdiction to use the Service. If you are accessing or using the Service on
                behalf of a company or other legal entity, you represent that you have the authority
                to bind such entity to these Terms.
              </Typography>
              <Typography variant="h4">2. Changes to Terms</Typography>
              <Typography variant="body1">
                We reserve the right, at our sole discretion, to modify or replace these Terms at
                any time. If a revision is material, we will provide at least 30 days' notice prior
                to any new terms taking effect. What constitutes a material change will be
                determined at our sole discretion. By continuing to access or use our Service after
                those revisions become effective, you agree to be bound by the revised terms.
              </Typography>
              <Typography variant="h4">3. Privacy Policy</Typography>
              <Typography variant="body1">
                Your use of the Service is also governed by our Privacy Policy, which explains how
                we collect, use, and disclose information about you. Please review our Privacy
                Policy at [Link to your Privacy Policy] to understand our practices.
              </Typography>
              <Typography variant="h4">4. User Accounts</Typography>
              <Typography variant="body1">
                Account Creation: To access certain features of the Service, you may be required to
                register for an account. You agree to provide accurate, current, and complete
                information during the registration process and to update such information to keep
                it accurate, current, and complete.
              </Typography>
              <Typography variant="body1">
                Account Security: You are responsible for safeguarding the password that you use to
                access the Service and for any activities or actions under your password. You agree
                not to disclose your password to any third party. You must notify us immediately
                upon becoming aware of any breach of security or unauthorized use of your account.
              </Typography>
              <Typography variant="body1">
                Account Termination: We may suspend or terminate your account and access to the
                Service immediately, without prior notice or liability, for any reason whatsoever,
                including without limitation if you breach the Terms.
              </Typography>
              <Typography variant="h4">5. User Conduct</Typography>
              <Typography variant="body1">
                You agree to use the Service only for lawful purposes and in a way that does not
                infringe the rights of, restrict, or inhibit anyone else's use and enjoyment of the
                Service. Prohibited behavior includes harassing or causing distress or inconvenience
                to any other user, transmitting obscene or offensive content, or disrupting the
                normal flow of dialogue within the Service.
              </Typography>
              <Typography variant="body1">
                You agree not to:
                <ul>
                  <li>
                    Use the Service in any way that violates any applicable national or
                    international law or regulation.
                  </li>
                  <li>
                    Engage in any conduct that restricts or inhibits anyone's use or enjoyment of
                    the Service, or which, as determined by us, may harm us or users of the Service
                    or expose them to liability.
                  </li>
                  <li>
                    Use the Service to transmit any unsolicited or unauthorized advertising or
                    promotional material or any other form of similar solicitation (spam).
                  </li>
                  <li>
                    Impersonate or attempt to impersonate [Your Company Name], a [Your Company Name]
                    employee, another user, or any other person or entity.
                  </li>
                  <li>
                    Introduce any viruses, Trojan horses, worms, logic bombs, or other material that
                    is malicious or technologically harmful.
                  </li>
                </ul>
              </Typography>
              <Typography variant="h4">6. Intellectual Property</Typography>
              The Service and its original content (excluding content provided by users), features,
              and functionality are and will remain the exclusive property of [Your Company Name]
              and its licensors. The Service is protected by copyright, trademark, and other laws of
              both the [Your Country] and foreign countries. Our trademarks and trade dress may not
              be used in connection with any product or service without the prior written consent of
              [Your Company Name].
              <Typography variant="h4">7. User-Generated Content</Typography>
              If the Service allows you to post, link, store, share, and otherwise make available
              certain information, text, graphics, videos, or other material ("Content"), you are
              responsible for the Content that you post on or through the Service, including its
              legality, reliability, and appropriateness. By posting Content to the Service, you
              grant us the right and license to use, modify, publicly perform, publicly display,
              reproduce, and distribute such Content on and through the Service. You retain any and
              all of your rights to any Content you submit, post or display on or through the
              Service and you are responsible for protecting those rights. You represent and warrant
              that: (i) the Content is yours (you own it) or you have the right to use it and grant
              us the rights and license as provided in these Terms, and (ii) the posting of your
              Content on or through the Service does not violate the privacy rights, publicity
              rights, copyrights, contract rights or any other rights of any person.
              <Typography variant="h4">8. Links to Other Websites</Typography>
              Our Service may contain links to third-party web sites or services that are not owned
              or controlled by [Your Company Name]. [Your Company Name] has no control over, and
              assumes no responsibility for, the content, privacy policies, or practices of any
              third-party web sites or services. You further acknowledge and agree that [Your
              Company Name] shall not be responsible or liable, directly or indirectly, for any
              damage or loss caused or alleged to be caused by or in connection with use of or
              reliance on any such content, goods or services available on or through any such web
              sites or services. We strongly advise you to read the terms and conditions and privacy
              policies of any third-party web sites or services that you visit.
              <Typography variant="h4">9. Disclaimer of Warranties</Typography>
              Your use of the Service is at your sole risk. The Service is provided on an "AS IS"
              and "AS AVAILABLE" basis. The Service is provided without warranties of any kind,
              whether express or implied, including, but not limited to, implied warranties of
              merchantability, fitness for a particular purpose, non-infringement or course of
              performance. [Your Company Name] its subsidiaries, affiliates, and its licensors do
              not warrant that a) the Service will function uninterrupted, secure or available at
              any particular time or location; b) any errors or defects will be corrected; c) the
              Service is free of viruses or other harmful components; or d) the results of using the
              Service will meet your requirements.
              <Typography variant="h4">10. Limitation of Liability</Typography>
              In no event shall [Your Company Name], nor its directors, employees, partners, agents,
              suppliers, or affiliates, be liable for any indirect, incidental, special,
              consequential or punitive damages, including without limitation, loss of profits,
              data, use, goodwill, or other intangible losses, resulting from (i) your access to or
              use of or inability to access or use the Service; (ii) any conduct or content of any
              third party on the Service; (iii) any content obtained from the Service; and (iv)
              unauthorized access, use or alteration of your transmissions or content, whether based
              on warranty, contract, tort (including negligence) or any other legal theory, whether
              or not we have been informed of the possibility of such damage, and even if a remedy
              set forth herein is found to have failed of its essential purpose.
              <Typography variant="h4">11. Indemnification</Typography>
              You agree to defend, indemnify and hold harmless [Your Company Name] and its licensee
              and licensors, and their employees, contractors, agents, officers and directors, from
              and against any and all claims, damages, obligations, losses, liabilities, costs or
              debt, and expenses (including but not limited to attorney's fees), resulting from or
              arising out of a) your use and access of the Service, by you or any person using your
              account and password; b) a breach of these Terms; or c) Content posted on the Service.
              <Typography variant="h4">12. Governing Law</Typography>
              These Terms shall be governed and construed in accordance with the laws of [Your
              State/Country], without regard to its conflict of law provisions. Our failure to
              enforce any right or provision of these Terms will not be considered a waiver of those
              rights. If any provision of these Terms is held to be invalid or unenforceable by a
              court, the remaining provisions of these Terms will remain in effect. These Terms
              constitute the entire agreement between us regarding our Service, and supersede and
              replace any prior agreements we might have between us regarding the Service.
              <Typography variant="h4">13. Contact Us</Typography>
              If you have any questions about these Terms, please contact us: By email: [Your Email
              Address] By visiting this page on our website: [Link to your Contact Us page]
            </Typography>
          </FormControl>
          <Typography
            variant="body1"
            sx={{
              alignSelf: 'flex-end',
            }}
          ></Typography>

          <Button variant="contained" fullWidth onClick={handleSignTOS}>
            Acknowledge
          </Button>
        </Stack>
      </Stack>
      <Suspense
        fallback={
          <Skeleton variant="rectangular" height={1} width={1} sx={{ bgcolor: 'primary.main' }} />
        }
      ></Suspense>
    </Stack>
  );
};

export default TermsOfService;
