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/service_categories/service_categoriesSlice'
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 Service_categoriesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { service_categories } = useAppSelector((state) => state.service_categories)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>SortOrderNote</p>
                    <p>{service_categories?.sort_order_note}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='IsActive'>
                    <SwitchField
                      field={{name: 'is_active', value: service_categories?.is_active}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>IconImages</p>
                    {service_categories?.icon_images?.length
                      ? (
                        <ImageField
                          name={'icon_images'}
                          image={service_categories?.icon_images}
                          className='w-20 h-20'
                        />
                      ) : <p>No IconImages</p>
                    }
                </div>
              

              
              

                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Service_listings Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                <th>PricingModel</th>
                                
                                
                                
                                <th>StartingPrice</th>
                                
                                
                                
                                <th>DeliveryDays</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>IsFeatured</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {service_categories.service_listings_category && Array.isArray(service_categories.service_listings_category) &&
                              service_categories.service_listings_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/service_listings/service_listings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="pricing_model">
                                        { item.pricing_model }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="starting_price">
                                        { item.starting_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivery_days">
                                        { item.delivery_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_featured">
                                        { dataFormatter.booleanFormatter(item.is_featured) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!service_categories?.service_listings_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Jobs Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                <th>BudgetMin</th>
                                
                                
                                
                                <th>BudgetMax</th>
                                
                                
                                
                                <th>BudgetType</th>
                                
                                
                                
                                <th>DeadlineAt</th>
                                
                                
                                
                                <th>PostedAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>IsRemote</th>
                                
                                
                                
                                <th>LocationRequirement</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {service_categories.jobs_category && Array.isArray(service_categories.jobs_category) &&
                              service_categories.jobs_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/jobs/jobs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="budget_min">
                                        { item.budget_min }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="budget_max">
                                        { item.budget_max }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="budget_type">
                                        { item.budget_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deadline_at">
                                        { dataFormatter.dateTimeFormatter(item.deadline_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="posted_at">
                                        { dataFormatter.dateTimeFormatter(item.posted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_remote">
                                        { dataFormatter.booleanFormatter(item.is_remote) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="location_requirement">
                                        { item.location_requirement }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!service_categories?.jobs_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Service_categoriesView;