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/gig_levels/gig_levelsSlice'
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 Gig_levelsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { gig_levels } = useAppSelector((state) => state.gig_levels)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Gig</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{gig_levels?.gig?.title ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>LevelNumber</p>
                  <p>{gig_levels?.level_number || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

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

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>DurationMinutes</p>
                  <p>{gig_levels?.duration_minutes || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Bookings GigLevel</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>
                            {gig_levels.bookings_gig_level && Array.isArray(gig_levels.bookings_gig_level) &&
                              gig_levels.bookings_gig_level.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>
                        {!gig_levels?.bookings_gig_level?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Gig_levelsView;