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

import { Column } from "@/common/components/Matrix/Column";
import { Matrix } from "@/common/components/Matrix/Matrix";
import { ZoneModel } from "@/contracts/client.schemas";

export const ZoneListPage = () => {
	const { assetId } = useParams();
	if (!assetId) {
		throw new Error("assetId is required");
	}

	const columns: Column<ZoneModel>[] = [
		{
			name: "index",
			title: "Index",
		},
		{
			name: "name",
			title: "Name",
		},
	];

	return (
		<Matrix
			title="Zones"
			columns={columns}
			baseUrl="/api/zones"
			filters={{
				assetId,
			}}
			defaultSort={[
				{
					field: "index",
					direction: "asc",
				},
			]}
			notificationMethodPrefix="ZONES"
			getModelTitle={(x: ZoneModel) => x.name}
			canCreate={true}
			canView={true}
			canRemove={true}
		/>
	);
};
