'use client';
import React, { useState } from "react";
import TableComponent from "@/components/mutual/tableView/FullTableComp/component";
import Link from "next/link";
import CreateForm from "@/components/mutual/tableView/mutual/CreateForm";
import UpdateForm from "@/components/mutual/tableView/mutual/UpdateForm";
import ViewForm from "@/components/mutual/tableView/mutual/ViewForm";

import { ContentProps } from "@/validations/mutual/dashboard/props";
import { EyeIcon, PencilIcon, PlusCircle, ArrowLeftFromLineIcon } from "lucide-react";
import { getSchemaByLanguage } from "@/schemas/custom/building/parts/tenantSomething/schemas";


// This is a mock page dont use it
const superUserTenantSomething: React.FC<ContentProps> = ({ lang, translations, activePageUrl, mode }) => {
    const [selectedRow, setSelectedRow] = useState<any>(null);

    const getSchema = getSchemaByLanguage(lang)
    const isList = mode === 'shortList' || mode === 'fullList'
    const basePageUrl = `/panel/${lang}/${activePageUrl}?mode=`
    const pageUrl = `/panel/${lang}/${activePageUrl}?mode=list`
    const urls = { list: "http://localhost:3000/api/tst" }
    const initPaginationDefault = { page: 1, size: 10, orderFields: [], orderTypes: [], query: {} }
    const renderLastRowComponent = (reDirectUrl: string, IconToWrap: any) => {
        return (<Link className="flex items-center gap-2" replace href={reDirectUrl} ><IconToWrap /></Link>)
    }
    const redirectUrls = {
        table: {
            update: renderLastRowComponent(`${basePageUrl}=update`, PencilIcon),
            view: renderLastRowComponent(`${basePageUrl}=view`, EyeIcon),
        },
        page: {
            create: renderLastRowComponent(`${basePageUrl}=create`, PlusCircle),
        }
    }
    const schemas = { list: {} }
    const columns = [
        "firstName",
        "lastName",
        "email",
        "phoneNumber",
        "country",
        "description",
        "isDeleted",
        "isConfirmed",
        "createdAt",
        "updatedAt",
    ]
    const listWithTableProps = {
        urls: { list: "http://localhost:3000/api/tst" },
        schemas: schemas,
        translations: translations,
        columns: columns,
        redirectUrls: redirectUrls,
        initPagination: initPaginationDefault,
        setSelectedRow: setSelectedRow,
    }
    const CreateFormProps = {
        schemas: { create: getSchema.createSchema },
        labels: getSchema.labels,
        selectedRow: selectedRow,
    }
    const UpdateFormProps = {
        rollbackTo: pageUrl,
        schemas: { update: getSchema.updateSchema },
        labels: getSchema.labels,
        selectedRow: selectedRow,
    }
    const ViewFormProps = {
        rollbackTo: pageUrl,
        schemas: { view: getSchema.detailSchema },
        selectedRow: selectedRow,
        labels: getSchema.labels,
    }
    const RenderBackToList = <div onClick={() => setSelectedRow(null)}>
        {renderLastRowComponent(pageUrl, ArrowLeftFromLineIcon)}
    </div>
    const shortAddProps = { ...listWithTableProps, schemas: { table: getSchema.shortSchema }, columns: { table: getSchema.shortColumns } }
    const fullAddProps = { ...listWithTableProps, schemas: { table: getSchema.detailSchema }, columns: { table: getSchema.columns } }
    return (
        <>
            {/* {JSON.stringify(getSchema)} */}
            {!isList && RenderBackToList}
            {isList && mode === 'shortList' && <><TableComponent {...shortAddProps} /></>}
            {isList && mode === 'fullList' && <><TableComponent {...fullAddProps} /></>}
            {mode === 'create' && <CreateForm {...CreateFormProps} />}
            {mode === 'update' && <UpdateForm {...UpdateFormProps} />}
            {mode === 'view' && <ViewForm {...ViewFormProps} />}
        </>
    );
}


export default superUserTenantSomething