/* eslint-disable @next/next/no-img-element */
import React from "react";
import Head from "next/head";
import { GetServerSideProps } from "next/types";
// @Antd
import { Col, Row, Carousel, Button } from "antd";
// @i18n
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { RightOutlined, LeftOutlined } from "@ant-design/icons";
// @Images
import { BackgroundFill } from "../../public/images";
// @Layout
import { LayoutWrapper } from "../../src/components/layouts/wrapper";
// @Styled
import styles from "../../src/components/pages/news/index.module.less";
// @Interfaces
import {
  INews,
  ITestimonials,
} from "../../src/components/pages/news/interfaces";
// Components
import NewsCard from "../../src/components/pages/news/components/NewCard";
import { Testimonials } from "../../src/components/pages/news/components/Testimonials";
// @Hooks
import { useNews } from "../../src/components/pages/news/hooks/useNews";

export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
  return {
    props: {
      ...(await serverSideTranslations(locale as string, ["common", "news"])),
    },
  };
};

export default function News() {
  const { t } = useTranslation();

  const {
    newsData,
    getImage,
    testimonial,
    page,
    handleNextPage,
    handlePrevPage,
    totalPages,
    total
  } = useNews();

  return (
    <main className={"container ".concat(styles.wrapper__page)}>
      <Head>
        <title>{t("news:title")} | GHF</title>
        <meta name="description" content={t("news:info")} key="desc" />
      </Head>

      <section
        style={{
          background: `url(${BackgroundFill})`,
          backgroundSize: "cover",
          backgroundPosition: "-10px",
        }}
      >
        <Row className="wrapper__content">
          <Col className="wrapper__content--horizontal" sm={24}>
            <h1 className={styles.contact__title}>{t("news:title")}</h1>
            {newsData.length > 0 ? (
            <Row gutter={[16, 16]}>
              {newsData?.map((news: INews) => {
                return (
                  <Col xs={24} sm={12} md={8} lg={6} xl={6} key={news.id}>
                    <NewsCard
                      id={news.id}
                      attributes={news.attributes}
                      getImage={getImage}
                    />
                  </Col>
                );
              })}
            </Row>
            ) : (
              <h3>{t("news:notFound")}</h3>
            )}
          </Col>
          {(total > 0) && (
          <Row
            className={"wrapper__content--horizontal ".concat(
              styles.about__wrapper
            )}
          >
            <Col span={24}>
              <div className={styles.about__card}>
                <h3 className={styles.about__card__title}>
                  {/* {" "}
            {t("about:fundadores")} */}
                  Testimonios
                </h3>
                <Row justify="space-around">
                  <Button
                    className={styles.button_left}
                    type="text"
                    shape="circle"
                    icon={<LeftOutlined />}
                    onClick={handlePrevPage}
                    disabled={page === 1}
                  />
                  {testimonial?.map((items: ITestimonials) => {
                    return (
                      <Col xs={24} sm={8} key={items.id}>
                        <Testimonials
                          id={items.id}
                          attributes={items.attributes}
                          getImage={getImage}
                        />
                      </Col>
                    );
                  })}
                  <Button
                    className={styles.button_right}
                    type="text"
                    shape="circle"
                    icon={<RightOutlined />}
                    onClick={handleNextPage}
                    disabled={page === totalPages}
                  />
                </Row>
              </div>
            </Col>
          </Row>)}
        </Row>
      </section>
    </main>
  );
}

News.getLayout = function getLayout(page: React.ReactElement) {
  return <LayoutWrapper>{page}</LayoutWrapper>;
};
