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_colors/stone_colorsSlice'
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_colorsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { stone_colors } = useAppSelector((state) => state.stone_colors)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Hex</p>
                    <p>{stone_colors?.hex}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

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

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Stones Color</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_colors.stones_color && Array.isArray(stone_colors.stones_color) &&
                              stone_colors.stones_color.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_colors?.stones_color?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Stone_colorsView;