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/stone_categories/stone_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 Stone_categoriesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { stone_categories } = useAppSelector((state) => state.stone_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 stone_categories')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View stone_categories')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/stone_categories/stone_categories-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>NameArabic</p>
                    <p>{stone_categories?.name_ar}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Slug</p>
                    <p>{stone_categories?.slug}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>DescriptionArabic</p>
                  {stone_categories.description_ar
                    ? <p dangerouslySetInnerHTML={{__html: stone_categories.description_ar}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SortOrder</p>
                  <p>{stone_categories?.sort_order || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CategoryType</p>
                    <p>{stone_categories?.category_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Stones Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>NameArabic</th>
                                
                                
                                
                                <th>Slug</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ShortDescriptionArabic</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Density</th>
                                
                                
                                
                                <th>WaterAbsorption</th>
                                
                                
                                
                                <th>CompressiveStrength</th>
                                
                                
                                
                                <th>FlexuralStrength</th>
                                
                                
                                
                                <th>OriginType</th>
                                
                                
                                
                                <th>OriginCountry</th>
                                
                                
                                
                                <th>IsFeatured</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {stone_categories.stones_category && Array.isArray(stone_categories.stones_category) &&
                              stone_categories.stones_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/stones/stones-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name_ar">
                                        { item.name_ar }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="slug">
                                        { item.slug }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="short_description_ar">
                                        { item.short_description_ar }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="density">
                                        { item.density }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="water_absorption">
                                        { item.water_absorption }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="compressive_strength">
                                        { item.compressive_strength }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="flexural_strength">
                                        { item.flexural_strength }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="origin_type">
                                        { item.origin_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="origin_country">
                                        { item.origin_country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_featured">
                                        { dataFormatter.booleanFormatter(item.is_featured) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!stone_categories?.stones_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Stone_categoriesView;