import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/event_ticket_types/event_ticket_typesSlice'
import dataFormatter from '../../helpers/dataFormatter';
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";

const Event_ticket_typesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { event_ticket_types } = useAppSelector((state) => state.event_ticket_types)

    const { id } = router.query;

    function removeLastCharacter(str) {
      console.log(str,`str`)
      return str.slice(0, -1);
    }

    useEffect(() => {
        dispatch(fetch({ id }));
    }, [dispatch, id]);

    return (
      <>
          <Head>
              <title>{getPageTitle('View event_ticket_types')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View event_ticket_types')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/event_ticket_types/event_ticket_types-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>

                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Event</p>

                        <p>{event_ticket_types?.event?.name ?? 'No data'}</p>

                </div>

                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Name</p>
                    <p>{event_ticket_types?.name}</p>
                </div>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Price</p>
                  <p>{event_ticket_types?.price || 'No data'}</p>
                </div>

                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Currency</p>
                    <p>{event_ticket_types?.currency}</p>
                </div>

                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CapacityOverrides</p>
                  <p>{event_ticket_types?.capacity_overrides || 'No data'}</p>
                </div>

                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>properties</p>

                        <p>{event_ticket_types?.properties?.name ?? 'No data'}</p>

                </div>

                <>
                    <p className={'block font-bold mb-2'}>Event_tickets TicketType</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>

                                <th>Code</th>

                                <th>Status</th>

                                <th>QRSVG</th>

                                <th>IssuedToName</th>

                                <th>IssuedToEmail</th>

                            </tr>
                            </thead>
                            <tbody>
                            {event_ticket_types.event_tickets_ticket_type && Array.isArray(event_ticket_types.event_tickets_ticket_type) &&
                              event_ticket_types.event_tickets_ticket_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/event_tickets/event_tickets-view/?id=${item.id}`)}>

                                    <td data-label="code">
                                        { item.code }
                                    </td>

                                    <td data-label="status">
                                        { item.status }
                                    </td>

                                    <td data-label="qr_svg">
                                        { item.qr_svg }
                                    </td>

                                    <td data-label="issued_to_name">
                                        { item.issued_to_name }
                                    </td>

                                    <td data-label="issued_to_email">
                                        { item.issued_to_email }
                                    </td>

                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!event_ticket_types?.event_tickets_ticket_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>

                <BaseDivider />

                <BaseButton
                    color='info'
                    label='Back'
                    onClick={() => router.push('/event_ticket_types/event_ticket_types-list')}
                />
              </CardBox>
          </SectionMain>
      </>
    );
};

Event_ticket_typesView.getLayout = function getLayout(page: ReactElement) {
    return (
      <LayoutAuthenticated>
          {page}
      </LayoutAuthenticated>
    )
}

export default Event_ticket_typesView;
