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/shipping_carriers/shipping_carriersSlice'
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 Shipping_carriersView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { shipping_carriers } = useAppSelector((state) => state.shipping_carriers)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CarrierName</p>
                    <p>{shipping_carriers?.carrier_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>SupportPhone</p>
                    <p>{shipping_carriers?.support_phone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TrackingURLTemplate</p>
                    <p>{shipping_carriers?.tracking_url_template}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Shipping_methods Carrier</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>MethodName</th>
                                
                                
                                
                                <th>BaseCost</th>
                                
                                
                                
                                <th>FreeShippingThreshold</th>
                                
                                
                                
                                <th>ServiceLevel</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {shipping_carriers.shipping_methods_carrier && Array.isArray(shipping_carriers.shipping_methods_carrier) &&
                              shipping_carriers.shipping_methods_carrier.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/shipping_methods/shipping_methods-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="method_name">
                                        { item.method_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_cost">
                                        { item.base_cost }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="free_shipping_threshold">
                                        { item.free_shipping_threshold }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="service_level">
                                        { item.service_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="active">
                                        { dataFormatter.booleanFormatter(item.active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!shipping_carriers?.shipping_methods_carrier?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Shipments Carrier</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>TrackingNumber</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>ShippedAt</th>
                                
                                
                                
                                <th>DeliveredAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {shipping_carriers.shipments_carrier && Array.isArray(shipping_carriers.shipments_carrier) &&
                              shipping_carriers.shipments_carrier.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/shipments/shipments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="tracking_number">
                                        { item.tracking_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="shipped_at">
                                        { dataFormatter.dateTimeFormatter(item.shipped_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivered_at">
                                        { dataFormatter.dateTimeFormatter(item.delivered_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!shipping_carriers?.shipments_carrier?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Shipping_carriersView;