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/gigs/gigsSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
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 GigsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { gigs } = useAppSelector((state) => state.gigs)
    

    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 gigs')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View gigs')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/gigs/gigs-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TutorProfile</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{gigs?.tutor_profile?.headline ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GigTitle</p>
                    <p>{gigs?.title}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={gigs?.description} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Category</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{gigs?.category?.name_en ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>Tags</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>Tag</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {gigs.tags && Array.isArray(gigs.tags) &&
                              gigs.tags.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tags/tags-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    <td data-label="label">
                                        { item.label }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!gigs?.tags?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GigStatus</p>
                    <p>{gigs?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Impressions</p>
                  <p>{gigs?.impressions || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>TotalOrders</p>
                  <p>{gigs?.total_orders || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Rating</p>
                  <p>{gigs?.rating || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Gig_levels Gig</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>LevelNumber</th>
                                
                                
                                
                                <th>LevelName</th>
                                
                                
                                
                                <th>LevelDescription</th>
                                
                                
                                
                                <th>DeliverablesJSON</th>
                                
                                
                                
                                <th>Price</th>
                                
                                
                                
                                <th>DurationMinutes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {gigs.gig_levels_gig && Array.isArray(gigs.gig_levels_gig) &&
                              gigs.gig_levels_gig.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/gig_levels/gig_levels-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="level_number">
                                        { item.level_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deliverables_json">
                                        { item.deliverables_json }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price">
                                        { item.price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="duration_minutes">
                                        { item.duration_minutes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!gigs?.gig_levels_gig?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Bookings Gig</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>LevelNumberSnapshot</th>
                                
                                
                                
                                <th>LevelNameSnapshot</th>
                                
                                
                                
                                <th>Price</th>
                                
                                
                                
                                <th>PlatformFee</th>
                                
                                
                                
                                <th>TutorPayout</th>
                                
                                
                                
                                <th>BookingStatus</th>
                                
                                
                                
                                <th>EscrowStatus</th>
                                
                                
                                
                                <th>ScheduledAt</th>
                                
                                
                                
                                <th>AcceptedAt</th>
                                
                                
                                
                                <th>MilestoneSubmittedAt</th>
                                
                                
                                
                                <th>AutoReleaseAt</th>
                                
                                
                                
                                <th>CompletedAt</th>
                                
                                
                                
                                <th>DeliverableNotes</th>
                                
                                
                                
                                
                                
                                <th>RevisionCount</th>
                                
                                
                                
                                <th>RevisionReason</th>
                                
                                
                                
                                <th>JitsiMeetingID</th>
                                
                                
                                
                                <th>JitsiMeetingPassword</th>
                                
                                
                                
                                <th>AdminNote</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {gigs.bookings_gig && Array.isArray(gigs.bookings_gig) &&
                              gigs.bookings_gig.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/bookings/bookings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="level_number">
                                        { item.level_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="level_name">
                                        { item.level_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price">
                                        { item.price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="platform_fee">
                                        { item.platform_fee }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tutor_payout">
                                        { item.tutor_payout }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="escrow_status">
                                        { item.escrow_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scheduled_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="accepted_at">
                                        { dataFormatter.dateTimeFormatter(item.accepted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="milestone_submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.milestone_submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="auto_release_at">
                                        { dataFormatter.dateTimeFormatter(item.auto_release_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completed_at">
                                        { dataFormatter.dateTimeFormatter(item.completed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deliverable_notes">
                                        { item.deliverable_notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="revision_count">
                                        { item.revision_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="revision_reason">
                                        { item.revision_reason }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="jitsi_meet_meeting_id">
                                        { item.jitsi_meet_meeting_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="jitsi_meet_password">
                                        { item.jitsi_meet_password }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="admin_note">
                                        { item.admin_note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!gigs?.bookings_gig?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Invites Gig</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Message</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>RespondedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {gigs.invites_gig && Array.isArray(gigs.invites_gig) &&
                              gigs.invites_gig.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/invites/invites-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="message">
                                        { item.message }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="responded_at">
                                        { dataFormatter.dateTimeFormatter(item.responded_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!gigs?.invites_gig?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

GigsView.getLayout = function getLayout(page: ReactElement) {
    return (
      <LayoutAuthenticated
        
        permission={'READ_GIGS'}
        
      >
          {page}
      </LayoutAuthenticated>
    )
}

export default GigsView;