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/procedure_families/procedure_familiesSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const Procedure_familiesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { procedure_families } = useAppSelector((state) => state.procedure_families)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Modality</p>
                    <p>{procedure_families?.modality}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BodyRegion</p>
                    <p>{procedure_families?.body_region}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='Active'>
                    <SwitchField
                      field={{name: 'active', value: procedure_families?.active}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>organizations</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{procedure_families?.organizations?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Cpt_codes ProcedureFamily</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>CPTCode</th>
                                
                                
                                
                                <th>ShortDescription</th>
                                
                                
                                
                                <th>LongDescription</th>
                                
                                
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {procedure_families.cpt_codes_procedure_family && Array.isArray(procedure_families.cpt_codes_procedure_family) &&
                              procedure_families.cpt_codes_procedure_family.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/cpt_codes/cpt_codes-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="short_description">
                                        { item.short_description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="long_description">
                                        { item.long_description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="active">
                                        { dataFormatter.booleanFormatter(item.active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!procedure_families?.cpt_codes_procedure_family?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Authorization_cases ProcedureFamily</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Stage</th>
                                
                                
                                
                                <th>Urgency</th>
                                
                                
                                
                                <th>OrderingProviderName</th>
                                
                                
                                
                                <th>RenderingProviderName</th>
                                
                                
                                
                                <th>SiteOfService</th>
                                
                                
                                
                                <th>ScheduledDate</th>
                                
                                
                                
                                <th>DollarsAtRisk</th>
                                
                                
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                <th>SLAState</th>
                                
                                
                                
                                <th>InternalNotes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {procedure_families.authorization_cases_procedure_family && Array.isArray(procedure_families.authorization_cases_procedure_family) &&
                              procedure_families.authorization_cases_procedure_family.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/authorization_cases/authorization_cases-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="stage">
                                        { item.stage }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="urgency">
                                        { item.urgency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ordering_provider_name">
                                        { item.ordering_provider_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rendering_provider_name">
                                        { item.rendering_provider_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="site_of_service">
                                        { item.site_of_service }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scheduled_date">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dollars_at_risk">
                                        { item.dollars_at_risk }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sla_state">
                                        { item.sla_state }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="internal_notes">
                                        { item.internal_notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!procedure_families?.authorization_cases_procedure_family?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Payer_rules ProcedureFamily</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>VersionLabel</th>
                                
                                
                                
                                <th>VersionStatus</th>
                                
                                
                                
                                <th>EffectiveFrom</th>
                                
                                
                                
                                <th>EffectiveTo</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {procedure_families.payer_rules_procedure_family && Array.isArray(procedure_families.payer_rules_procedure_family) &&
                              procedure_families.payer_rules_procedure_family.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/payer_rules/payer_rules-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="version_label">
                                        { item.version_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="version_status">
                                        { item.version_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_from">
                                        { dataFormatter.dateTimeFormatter(item.effective_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_to">
                                        { dataFormatter.dateTimeFormatter(item.effective_to) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!procedure_families?.payer_rules_procedure_family?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Procedure_familiesView;