import { useParams } from "react-router-dom";

import { AssetModel } from "@/contracts/client.schemas";

import { Column, createColumn } from "../../../common/components/Matrix/Column";
import { Matrix } from "../../../common/components/Matrix/Matrix";

export const AssetListPage = () => {
	const { organizationId } = useParams();
	if (!organizationId) {
		throw new Error("Organization id is required");
	}

	const columns: Column<AssetModel>[] = [
		{
			name: "name",
			title: "Name",
		},
		createColumn("Description", "description", (value) => {
			if (!value) {
				return "-";
			}

			if (value.length > 50) {
				return value.slice(0, 50) + "...";
			}

			return value;
		}),
	];

	return (
		<Matrix
			baseUrl="/api/assets"
			title="Assets"
			columns={columns}
			getModelTitle={(model) => model.name}
			notificationMethodPrefix="ASSETS"
			filters={{ organizationId }}
			canCreate={true}
			canRemove={true}
			canView={true}
			useSearch={true}
		/>
	);
};
