"use client";

import DataTableWithAuth from "@/core/components/DataTableWithAuth";
import { GET_SYSTEM_MESSAGES_OPERATOR } from "@/core/utils/routes";
import { Box } from "@mui/material";
import { useMemo } from "react";
import moment from "jalali-moment";
import Player from "./Player";
const DataTable = () => {
    const columns = useMemo(
        () => [
            {
                accessorKey: "id",
                header: "کد یکتا",
                id: "id",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
            },
            {
                accessorKey: "type_name",
                header: "نوع",
                id: "type_name",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
            },
            {
                header: "تاریخ",
                id: "date",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
                Cell: ({ row }) =>
                    row.original.date ? moment(row.original.date).locale("fa").format("yyyy/MM/DD") : <>-</>,
            },
            {
                header: "ساعت",
                id: "time",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
                Cell: ({ row }) =>
                    row.original.date ? moment(row.original.date).locale("fa").format("HH:mm") : <>-</>,
            },
            {
                accessorKey: "duration",
                header: "طول تماس ( ثانیه )",
                id: "duration",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
            },
            {
                header: "پخش صدا",
                id: "player",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
                Cell: ({ row }) => <Player audioUrl={row.original.voice} messageId={row.original.id} />,
            },
        ],
        []
    );

    return (
        <Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
            <DataTableWithAuth
                need_filter={true}
                columns={columns}
                table_url={GET_SYSTEM_MESSAGES_OPERATOR}
                page_name={"systemMessagesPage"}
                table_name={"systemMessagesList"}
                positionActionsColumn={"last"}
            />
        </Box>
    );
};
export default DataTable;
