import { useEffect, useState, Fragment } from 'react';
import { DataTable } from '@/components/Shared/DataTable';

import 'mantine-datatable/styles.css';
import FilterOrders from '@/components/Orders/FilterOrders';
import { getStatusColorClass } from '@/lib/order-status-lib';
import { getAdminNotesLabel } from '@/lib/admin-notes-lib';
import { Dialog, Transition } from '@headlessui/react';

import Link from 'next/link';
import Tippy from '@tippyjs/react';
import 'tippy.js/dist/tippy.css';
import { coloredToast } from '@/lib/toast';
import { logActivity } from '@/utils/activityLogger';
import { formatRupiah } from '@/utils/formatRupiah';

interface Order {
    id: string;
    order_id: string;
    customer: {
        billing: {
            name: string;
            email: string;
            phone: string;
        };
        shipping: {
            name: string;
            phone: string;
            address: string;
            kecamatan: string;
            kelurahan: string;
            kota: string;
            provinsi: string;
            kodepos: string;
        };
    };
    order_shipment: {
        provider: string;
        service: string;
        tracking_code: string;
    };
    order_status: string;
    sub_total: number;
    order_date: Date;
    order_payment: {
        name: string;
    };
    on_proceed: boolean;
    order_items: [];
    is_preorder: boolean;
    admin_notes?: string;
}

interface Filter {
    payment_type: string;
    customer_name: string;
    date_range: string;
    admin_notes: string;
}

interface OrderProps {
    fetchCount: () => void;
}

const ProcessingOrders: React.FC<OrderProps> = ({ fetchCount }) => {
    const [showModalFilter, setShowModalFilter] = useState(false);
    const [isLoading, setIsLoading] = useState(true); // Add isLoading state
    const [appliedFilter, setAppliedFilter] = useState<Filter>({
        customer_name: '',
        payment_type: '',
        date_range: '',
        admin_notes: '',
    });
    const [isFiltered, setIsFiltered] = useState(false);

    const PAGE_SIZES = [5, 10, 20, 30, 50, 100];

    const savedPage = localStorage.getItem('datatable_page_processing_order');
    const savedPageSize = localStorage.getItem('datatable_pageSize_processing_order');
    const savedSearch = localStorage.getItem('datatable_search_processing_order');

    const [page, setPage] = useState(savedPage ? parseInt(savedPage, 10) : 1);
    const [pageSize, setPageSize] = useState(savedPageSize ? parseInt(savedPageSize, 10) : PAGE_SIZES[0]);
    const [search, setSearch] = useState(savedSearch || '');

    const [records, setRecords] = useState<Order[]>([]);
    const [totalRecords, setTotalRecords] = useState(0);

    // Save state to localStorage whenever there is a change
    useEffect(() => {
        localStorage.setItem('datatable_page_processing_order', page.toString());
        localStorage.setItem('datatable_pageSize_processing_order', pageSize.toString());
        localStorage.setItem('datatable_search_processing_order', search);
    }, [page, pageSize, search]);

    // Fetch data from API
    const fetchData = async () => {
        setIsLoading(true); // Set isLoading to true before fetching data
        try {
            let filter = '';

            if (appliedFilter.date_range) {
                const dateRange = appliedFilter.date_range.split(' to ');
                const startDate = dateRange[0];
                const endDate = dateRange[1];
                filter += `&minDate=${startDate}`;
                filter += `&maxDate=${endDate}`;
            }

            if (appliedFilter.customer_name) {
                filter += `&customer_name=${appliedFilter.customer_name}`;
            }

            if (appliedFilter.payment_type) {
                filter += `&payment_type=${appliedFilter.payment_type}`;
            }

            if (appliedFilter.admin_notes) {
                filter += `&admin_notes=${appliedFilter.admin_notes}`;
            }

            const api_url = process.env.API_URL;
            const response = await fetch(`${api_url}api/order/list?page=${page}&per_page=${pageSize}&status=Processing&q=${search}${filter}`, {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json',
                },
                credentials: 'include', // Include this option
            });
            const data = await response.json();

            setPage(data.currentPage);
            setTotalRecords(data.totalData);
            setRecords(data.data);

            setIsLoading(false); // Set isLoading to false after data is fetched
        } catch (error) {
            console.error('Error fetching data:', error);
            setIsLoading(false); // Set isLoading to false even if there's an error
        }
    };

    useEffect(() => {
        fetchData();
    }, [page, pageSize]);

    const [shippingModal, setShippingModal] = useState<boolean>(false);
    const [isOnDelivery, setIsOnDelivery] = useState<boolean>(false);
    const [shippingAction, setShippingAction] = useState<{ id: string; order_id: string; tracking_code: string }>({
        id: '',
        order_id: '',
        tracking_code: '',
    });

    const setIndelivery = (id: string, order_id: string, tracking_code: string) => {
        setShippingAction({
            id,
            order_id,
            tracking_code,
        });
        setShippingModal(true);
    };
    const setTrackingCode = (e: any) => {
        setShippingAction((prev: any) => {
            return {
                ...prev,
                tracking_code: e.target.value,
            };
        });
    };

    const setToShipped = async () => {
        setIsOnDelivery(true);
        if (!shippingAction.tracking_code) {
            coloredToast('warning', 'tracking code is required');
            setIsOnDelivery(false);
            return;
        }

        try {
            const payload = {
                tracking_code: shippingAction.tracking_code,
            };
            const api_url = process.env.API_URL;
            const fetchUrl = `${api_url}api/order/set-in-delivery/${shippingAction.id}`;
            const response = await fetch(fetchUrl, {
                method: 'PUT',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(payload),
                credentials: 'include', // Include this option
            });

            if (!response.ok) {
                const res = await response.json();
                throw new Error(res.message);
            }
        } catch (error: any) {
            coloredToast('warning', error.message || 'something went wrong');
            await logActivity({
                location: 'Set In Delivery',
                description: `Order - ${shippingAction.order_id} status gagal di update: ${error.message}`,
            });
            setIsOnDelivery(false);
            return;
        }
        coloredToast('success', 'order status changed to In Delivery');
        setShippingModal(false);
        setIsOnDelivery(false);
        await logActivity({
            location: 'Set In Delivery',
            description: `Order - ${shippingAction.order_id} status changed to In Delivery`,
        });
        fetchData();
        fetchCount();
    };

    const handleKeypress = (event: React.KeyboardEvent<HTMLInputElement>) => {
        if (event.keyCode === 13) {
            if (page !== 1) {
                setPage(1);
            } else {
                fetchData();
            }
        }
    };

    const applyFilter = () => {
        setIsFiltered(true);
        setShowModalFilter(false);
        if (page !== 1) {
            setPage(1);
        } else {
            fetchData();
        }
    };

    const removeFilter = () => {
        setAppliedFilter({
            ...appliedFilter,
            payment_type: '',
            customer_name: '',
            date_range: '',
            admin_notes: '',
        });
        setIsFiltered(false);
    };

    useEffect(() => {
        if (!isFiltered) {
            fetchData();
        }
    }, [isFiltered]);
    return (
        <>
            <FilterOrders showModalFilter={showModalFilter} setShowModalFilter={setShowModalFilter} appliedFilter={appliedFilter} setAppliedFilter={setAppliedFilter} applyFilter={applyFilter} />
            <div className="panel border-white-light px-0 dark:border-[#1b2e4b]">
                <div className="invoice-table">
                    <div className="mb-4.5 flex flex-col gap-5 px-5 md:flex-row md:items-center">
                        <div className="flex items-center">
                            <Tippy content="Filter">
                                <button type="button" className={`flex items-center hover:text-primary ${isFiltered ? 'text-primary' : ''}`} onClick={() => setShowModalFilter(true)}>
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                                        <path
                                            opacity="0.5"
                                            d="M2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2C16.714 2 19.0711 2 20.5355 3.46447C22 4.92893 22 7.28595 22 12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12Z"
                                            stroke="currentColor"
                                            strokeWidth="1.5"
                                        />
                                        <path
                                            d="M10 14C11.1046 14 12 14.8954 12 16C12 17.1046 11.1046 18 10 18C8.89543 18 8 17.1046 8 16C8 14.8954 8.89543 14 10 14Z"
                                            stroke="currentColor"
                                            strokeWidth="1.5"
                                        />
                                        <circle cx="2" cy="2" r="2" transform="matrix(-4.37114e-08 -1 -1 4.37114e-08 16 10)" stroke="currentColor" strokeWidth="1.5" />
                                        <path d="M14 16L19 16" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                        <path d="M10 8L5 8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                        <path d="M5 16L6 16" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                        <path d="M19 8L18 8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                    </svg>
                                </button>
                            </Tippy>
                            {isFiltered && (
                                <div className="badge badge-outline-danger ms-2 cursor-pointer " onClick={() => removeFilter()}>
                                    <span className="flex items-center">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                                            <path d="M14.5 9.50002L9.5 14.5M9.49998 9.5L14.5 14.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                        </svg>
                                        Remove Filter
                                    </span>
                                </div>
                            )}
                        </div>
                        <div className="ltr:ml-auto rtl:mr-auto">
                            <input type="text" className="form-input w-auto" placeholder="Search Order ID" value={search} onChange={(e) => setSearch(e.target.value)} onKeyDown={handleKeypress} />
                        </div>
                    </div>

                    <div className="datatables pagination-padding">
                        {isLoading ? (
                            // Show loading indicator here
                            <div className="flex justify-center py-4 text-center">
                                <svg
                                    viewBox="0 0 24 24"
                                    width="24"
                                    height="24"
                                    stroke="currentColor"
                                    strokeWidth="1.5"
                                    fill="none"
                                    strokeLinecap="round"
                                    strokeLinejoin="round"
                                    className="h-5 w-5 animate-spin text-white-dark"
                                >
                                    <line x1="12" y1="2" x2="12" y2="6"></line>
                                    <line x1="12" y1="18" x2="12" y2="22"></line>
                                    <line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line>
                                    <line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line>
                                    <line x1="2" y1="12" x2="6" y2="12"></line>
                                    <line x1="18" y1="12" x2="22" y2="12"></line>
                                    <line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line>
                                    <line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line>
                                </svg>
                                <span className="ms-3">Please wait, we&apos;re still working to load the data...</span>
                            </div>
                        ) : (
                            <DataTable
                                className="table-hover whitespace-nowrap"
                                records={records}
                                minHeight={250}
                                noRecordsText="No data found"
                                columns={[
                                    {
                                        accessor: 'order id',
                                        render: ({ order_id, order_items, is_preorder }) => {
                                            const link = (
                                                <Link href={`/orders/edit/${order_id}`}>
                                                    <div className="text-xs font-semibold underline hover:no-underline">{`#${order_id}`}</div>
                                                </Link>
                                            );

                                            const clickAndCollect = order_items && order_items.filter((order: any) => order.pick_in_store_code).length > 0 && (
                                                <span className="mt-2 italic text-secondary">C&C | </span>
                                            );

                                            const stores =
                                                order_items &&
                                                order_items
                                                    .filter((order: any) => order.pick_in_store_code)
                                                    .map((order: any, index: number) => {
                                                        let store =
                                                            order.collect_in_store === 'Grand Indonesia'
                                                                ? 'GI'
                                                                : order.collect_in_store === 'Kota Kasablanka'
                                                                    ? 'Kokas'
                                                                    : order.collect_in_store === 'Pakuwon Mall Bekasi'
                                                                        ? 'PKWBKS'
                                                                        : !order.collect_in_store && order.pick_in_store_code
                                                                            ? 'online'
                                                                            : '';

                                                        const comma = index !== order_items.length - 1 ? ', ' : '';

                                                        return (
                                                            <span key={index} className="mt-2 italic text-secondary">
                                                                {store}
                                                                {comma}
                                                            </span>
                                                        );
                                                    });

                                            return (
                                                <>
                                                    {link}
                                                    {clickAndCollect}
                                                    {stores}
                                                    {is_preorder && <div className="mt-2 text-xs text-info">Pre-order</div>}
                                                </>
                                            );
                                        },
                                    },
                                    {
                                        accessor: 'name',
                                        render: ({ customer }) => (
                                            <>
                                                <div className="flex items-center text-sm font-bold uppercase">
                                                    <div>{customer.billing.name}</div>
                                                </div>
                                                <div className="text-xs	">{customer.billing.email}</div>
                                                <div className="text-xs	">{customer.billing.phone}</div>
                                            </>
                                        ),
                                    },
                                    {
                                        accessor: 'status',
                                        render: ({ order_status, on_proceed }) => (
                                            <div className="flex items-center justify-center">
                                                {on_proceed && <div className="mr-1 h-2 w-2 rounded-full bg-primary"></div>}
                                                <span className={`flex w-24 justify-center badge badge-nb ${getStatusColorClass(order_status)} `}>{order_status}</span>
                                            </div>
                                        ),
                                    },
                                    {
                                        accessor: 'admin_notes',
                                        title: 'Admin Notes',
                                        render: ({ admin_notes }) => <span className="text-xs">{getAdminNotesLabel(admin_notes)}</span>,
                                    },
                                    {
                                        accessor: 'shipping',
                                        render: ({ customer, order_shipment }) => (
                                            <>
                                                <div className="font-semibold">
                                                    {customer.shipping.name} ({customer.shipping.phone})
                                                </div>
                                                <div className="whitespace-normal text-sm lowercase	">
                                                    {[customer.shipping.address, customer.shipping.kelurahan, customer.shipping.kecamatan, customer.shipping.kota, customer.shipping.provinsi, customer.shipping.kodepos]
                                                        .filter(Boolean)
                                                        .join(', ')}
                                                </div>
                                                <div className="text-xs text-white-dark	">
                                                    {order_shipment.provider} - {order_shipment.service}
                                                </div>
                                            </>
                                        ),
                                    },
                                    {
                                        accessor: 'date',
                                        render: ({ order_date }) => {
                                            const orderDate = new Date(order_date);
                                            const formattedDate = orderDate.toLocaleDateString('id-ID'); // Format the date
                                            const formattedTime = orderDate.toLocaleTimeString('id-ID'); // Format the time
                                            const formattedDateTime = `${formattedDate} ${formattedTime}`; // Combine date and time
                                            return (
                                                <>
                                                    <div className="text-center text-xs">
                                                        <div>{formattedDate}</div>
                                                        <div>{formattedTime}</div>
                                                    </div>
                                                </>
                                            ); // Render the formatted date and time
                                        },
                                    },
                                    {
                                        accessor: 'amount',
                                        titleClassName: 'text-right',
                                        render: ({ sub_total }) => <div className="text-right font-semibold">{formatRupiah(sub_total, 'Rp')}</div>,
                                    },
                                    {
                                        accessor: 'payment',
                                        render: ({ order_payment }) => <>{order_payment.name}</>,
                                    },

                                    {
                                        accessor: 'action',
                                        title: 'Actions',
                                        textAlign: 'center',
                                        render: ({ id, order_id, order_shipment }) => (
                                            <div className="flex">
                                                <div className="mx-1 flex w-max items-center gap-4">
                                                    <Link href={`/orders/edit/${order_id}`} className="flex hover:text-info">
                                                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" className="h-4.5 w-4.5">
                                                            <path
                                                                opacity="0.5"
                                                                d="M22 10.5V12C22 16.714 22 19.0711 20.5355 20.5355C19.0711 22 16.714 22 12 22C7.28595 22 4.92893 22 3.46447 20.5355C2 19.0711 2 16.714 2 12C2 7.28595 2 4.92893 3.46447 3.46447C4.92893 2 7.28595 2 12 2H13.5"
                                                                stroke="currentColor"
                                                                strokeWidth="1.5"
                                                                strokeLinecap="round"
                                                            ></path>
                                                            <path
                                                                d="M17.3009 2.80624L16.652 3.45506L10.6872 9.41993C10.2832 9.82394 10.0812 10.0259 9.90743 10.2487C9.70249 10.5114 9.52679 10.7957 9.38344 11.0965C9.26191 11.3515 9.17157 11.6225 8.99089 12.1646L8.41242 13.9L8.03811 15.0229C7.9492 15.2897 8.01862 15.5837 8.21744 15.7826C8.41626 15.9814 8.71035 16.0508 8.97709 15.9619L10.1 15.5876L11.8354 15.0091C12.3775 14.8284 12.6485 14.7381 12.9035 14.6166C13.2043 14.4732 13.4886 14.2975 13.7513 14.0926C13.9741 13.9188 14.1761 13.7168 14.5801 13.3128L20.5449 7.34795L21.1938 6.69914C22.2687 5.62415 22.2687 3.88124 21.1938 2.80624C20.1188 1.73125 18.3759 1.73125 17.3009 2.80624Z"
                                                                stroke="currentColor"
                                                                strokeWidth="1.5"
                                                            ></path>
                                                            <path
                                                                opacity="0.5"
                                                                d="M16.6522 3.45508C16.6522 3.45508 16.7333 4.83381 17.9499 6.05034C19.1664 7.26687 20.5451 7.34797 20.5451 7.34797M10.1002 15.5876L8.4126 13.9"
                                                                stroke="currentColor"
                                                                strokeWidth="1.5"
                                                            ></path>
                                                        </svg>
                                                    </Link>
                                                </div>
                                                <div className="mx-1 flex w-max items-center gap-4">
                                                    <Link href={`/orders/packing-slip/${order_id}`} target="_blank" className="flex hover:text-info">
                                                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                            <path
                                                                d="M3 10C3 6.22876 3 4.34315 4.17157 3.17157C5.34315 2 7.22876 2 11 2H13C16.7712 2 18.6569 2 19.8284 3.17157C21 4.34315 21 6.22876 21 10V14C21 17.7712 21 19.6569 19.8284 20.8284C18.6569 22 16.7712 22 13 22H11C7.22876 22 5.34315 22 4.17157 20.8284C3 19.6569 3 17.7712 3 14V10Z"
                                                                stroke="currentColor"
                                                                strokeWidth="1.5"
                                                            />
                                                            <path d="M8 12H16" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                                            <path d="M8 8H16" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                                            <path d="M8 16H13" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                                                        </svg>
                                                    </Link>
                                                </div>
                                                <div
                                                    className="mx-1 flex w-max items-center gap-4 hover:cursor-pointer hover:text-primary"
                                                    onClick={() => setIndelivery(id, order_id, order_shipment.tracking_code)}
                                                >
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none">
                                                        <rect x="16" y="13" width="6" height="6" rx="3" stroke="#1C274C" strokeWidth="1.5" />
                                                        <path
                                                            d="M11 16V14.5C11 12.6144 11 11.6716 10.4142 11.0858C9.82843 10.5 8.88562 10.5 7 10.5H6.4C6.02856 10.5 5.84284 10.5 5.68616 10.5123C3.72466 10.6667 2.1667 12.2247 2.01233 14.1862C2 14.3428 2 14.5286 2 14.9C2 14.9929 2 15.0393 2.00308 15.0785C2.04168 15.5688 2.43116 15.9583 2.92154 15.9969C2.96071 16 3.00714 16 3.1 16H11ZM11 16H16"
                                                            stroke="currentColor"
                                                            strokeWidth="1.5"
                                                            strokeLinecap="round"
                                                        />
                                                        <path
                                                            opacity="0.5"
                                                            d="M9.5 16C9.5 17.6569 8.15685 19 6.5 19C4.84315 19 3.5 17.6569 3.5 16"
                                                            stroke="currentColor"
                                                            strokeWidth="1.5"
                                                            strokeLinecap="round"
                                                        />
                                                        <path
                                                            d="M12 5H12.5279C13.7307 5 14.3321 5 14.8154 5.2987C15.2987 5.5974 15.5677 6.13531 16.1056 7.21114L19 13"
                                                            stroke="currentColor"
                                                            strokeWidth="1.5"
                                                            strokeLinecap="round"
                                                        />
                                                        <path
                                                            opacity="0.5"
                                                            d="M18.1426 11L18.8243 10.4978C19.0871 10.3041 19.2186 10.2073 19.31 10.0811C19.3722 9.99519 19.4203 9.89994 19.4526 9.7989C19.5 9.65046 19.5 9.48721 19.5 9.16072C19.5 8.54327 19.5 8.23455 19.3684 8.00405C19.2797 7.84887 19.1511 7.72028 18.996 7.63165C18.7654 7.5 18.4567 7.5 17.8393 7.5H16.5"
                                                            stroke="#1C274C"
                                                            strokeWidth="1.5"
                                                            strokeLinecap="round"
                                                        />
                                                    </svg>
                                                </div>
                                            </div>
                                        ),
                                    },
                                ]}
                                highlightOnHover
                                totalRecords={totalRecords}
                                recordsPerPage={pageSize}
                                page={page}
                                onPageChange={(p) => setPage(p)}
                                recordsPerPageOptions={PAGE_SIZES}
                                onRecordsPerPageChange={setPageSize}
                                paginationText={({ from, to, totalRecords }) => `Showing  ${from} to ${to} of ${totalRecords} orders`}
                            />
                        )}
                    </div>
                </div>
            </div>
            <Transition appear show={shippingModal} as={Fragment}>
                <Dialog as="div" open={shippingModal} onClose={() => setShippingModal(false)} className="relative z-50">
                    <Transition.Child as={Fragment} enter="ease-out duration-300" enterFrom="opacity-0" enterTo="opacity-100" leave="ease-in duration-200" leaveFrom="opacity-100" leaveTo="opacity-0">
                        <div className="fixed inset-0 bg-[black]/60" />
                    </Transition.Child>
                    <div className="fixed inset-0 overflow-y-auto">
                        <div className="flex min-h-full items-center justify-center px-4 py-8">
                            <Transition.Child
                                as={Fragment}
                                enter="ease-out duration-300"
                                enterFrom="opacity-0 scale-95"
                                enterTo="opacity-100 scale-100"
                                leave="ease-in duration-200"
                                leaveFrom="opacity-100 scale-100"
                                leaveTo="opacity-0 scale-95"
                            >
                                <Dialog.Panel className="panel w-full max-w-lg overflow-hidden rounded-lg border-0 p-0 text-black dark:text-white-dark">
                                    <button
                                        type="button"
                                        onClick={() => setShippingModal(false)}
                                        className="absolute top-4 text-gray-400 outline-none hover:text-gray-800 ltr:right-4 rtl:left-4 dark:hover:text-gray-600"
                                    >
                                        <svg
                                            xmlns="http://www.w3.org/2000/svg"
                                            width="24"
                                            height="24"
                                            viewBox="0 0 24 24"
                                            fill="none"
                                            stroke="currentColor"
                                            strokeWidth="1.5"
                                            strokeLinecap="round"
                                            strokeLinejoin="round"
                                        >
                                            <line x1="18" y1="6" x2="6" y2="18"></line>
                                            <line x1="6" y1="6" x2="18" y2="18"></line>
                                        </svg>
                                    </button>
                                    <div className="bg-[#fbfbfb] py-3 text-lg font-medium ltr:pl-5 ltr:pr-[50px] rtl:pl-[50px] rtl:pr-5 dark:bg-[#121c2c]">#{shippingAction.order_id}</div>
                                    <div className="p-5">
                                        <form>
                                            <div className="mb-5">
                                                <label htmlFor="name">Tracking Code</label>
                                                <input
                                                    id="tracking_code"
                                                    type="text"
                                                    placeholder="Enter Tracking Code"
                                                    className="form-input"
                                                    value={shippingAction.tracking_code}
                                                    onChange={(e) => setTrackingCode(e)}
                                                />
                                            </div>

                                            <div className="mt-8 flex items-center justify-end">
                                                <button type="button" className="btn btn-outline-danger" onClick={() => setShippingModal(false)}>
                                                    Cancel
                                                </button>
                                                <button type="button" disabled={isOnDelivery} className="btn btn-primary ltr:ml-4 rtl:mr-4" onClick={setToShipped}>
                                                    Set to In Delivery
                                                </button>
                                            </div>
                                        </form>
                                    </div>
                                </Dialog.Panel>
                            </Transition.Child>
                        </div>
                    </div>
                </Dialog>
            </Transition>
        </>
    );
};
export default ProcessingOrders;
