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/menstrual_cycles/menstrual_cyclesSlice'
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 Menstrual_cyclesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { menstrual_cycles } = useAppSelector((state) => state.menstrual_cycles)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>User</p>
                    
                    
                        <p>{menstrual_cycles?.user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              
                <FormField label='PeriodStart'>
                    {menstrual_cycles.period_start ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={menstrual_cycles.period_start ?
                        new Date(
                          dayjs(menstrual_cycles.period_start).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No PeriodStart</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='PeriodEnd'>
                    {menstrual_cycles.period_end ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={menstrual_cycles.period_end ?
                        new Date(
                          dayjs(menstrual_cycles.period_end).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No PeriodEnd</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='BreakthroughBleeding'>
                    <SwitchField
                      field={{name: 'breakthrough_bleeding', value: menstrual_cycles?.breakthrough_bleeding}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Menstrual_day_logs Cycle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>LogDate</th>
                                
                                
                                
                                <th>FlowIntensity</th>
                                
                                
                                
                                <th>Cramping(1-10)</th>
                                
                                
                                
                                <th>Bloating(1-5)</th>
                                
                                
                                
                                <th>Acne</th>
                                
                                
                                
                                <th>BreastTenderness</th>
                                
                                
                                
                                <th>Headache</th>
                                
                                
                                
                                <th>Fatigue</th>
                                
                                
                                
                                <th>FoodCravings</th>
                                
                                
                                
                                <th>LowerBackPain</th>
                                
                                
                                
                                <th>Clotting</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {menstrual_cycles.menstrual_day_logs_cycle && Array.isArray(menstrual_cycles.menstrual_day_logs_cycle) &&
                              menstrual_cycles.menstrual_day_logs_cycle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/menstrual_day_logs/menstrual_day_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="log_date">
                                        { dataFormatter.dateTimeFormatter(item.log_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="flow_intensity">
                                        { item.flow_intensity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cramping">
                                        { item.cramping }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bloating">
                                        { item.bloating }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="acne">
                                        { dataFormatter.booleanFormatter(item.acne) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="breast_tenderness">
                                        { dataFormatter.booleanFormatter(item.breast_tenderness) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="headache">
                                        { dataFormatter.booleanFormatter(item.headache) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="fatigue">
                                        { dataFormatter.booleanFormatter(item.fatigue) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="food_cravings">
                                        { dataFormatter.booleanFormatter(item.food_cravings) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lower_back_pain">
                                        { dataFormatter.booleanFormatter(item.lower_back_pain) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clotting">
                                        { dataFormatter.booleanFormatter(item.clotting) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!menstrual_cycles?.menstrual_day_logs_cycle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Menstrual_cyclesView;