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/license_products/license_productsSlice'
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 License_productsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { license_products } = useAppSelector((state) => state.license_products)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProductCode</p>
                    <p>{license_products?.product_code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ProductName</p>
                    <p>{license_products?.product_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Version</p>
                    <p>{license_products?.version}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>License_keys Product</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>LicenseCode</th>
                                
                                
                                
                                <th>LicenseType</th>
                                
                                
                                
                                <th>IssuedAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>HardwareFingerprint</th>
                                
                                
                                
                                <th>ServerFingerprint</th>
                                
                                
                                
                                <th>DatabaseFingerprint</th>
                                
                                
                                
                                <th>AllowedClients</th>
                                
                                
                                
                                <th>AllowUpdates</th>
                                
                                
                                
                                <th>LastErrorMessage</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {license_products.license_keys_product && Array.isArray(license_products.license_keys_product) &&
                              license_products.license_keys_product.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/license_keys/license_keys-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="license_code">
                                        { item.license_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_type">
                                        { item.license_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="issued_at">
                                        { dataFormatter.dateTimeFormatter(item.issued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="hardware_fingerprint">
                                        { item.hardware_fingerprint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="server_fingerprint">
                                        { item.server_fingerprint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="db_fingerprint">
                                        { item.db_fingerprint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allowed_clients">
                                        { item.allowed_clients }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allow_updates">
                                        { dataFormatter.booleanFormatter(item.allow_updates) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_error_message">
                                        { item.last_error_message }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!license_products?.license_keys_product?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default License_productsView;