import { useState } from 'react';
import Request from '../../utils/request';
export interface DustRecordProps {
	id: number;
	name: string;
	batch: string;
	provider_name: string;
	created_time: string;
	approve_time: string;
	state: keyof typeof DustState;
	channel_id: number;
	status: keyof typeof DustStatusConfis;
	type_code: number;
}
export const DustState = {
	0: '离线',
	1: '在线',
};

export enum DustStatus {
	'wait',
	'agree',
	'Refuse',
}
export const DustStatusConfis = {
	[DustStatus.wait]: '待确认',
	[DustStatus.agree]: '已确认',
	[DustStatus.Refuse]: '非本项目',
};
/**
 * @description 扬尘设备列表
 */
export const useDustList = () => {
	const [state, setState] = useState<{
		loading: boolean;
		dataSource: DustRecordProps[];
		total: number;
		current: number;
	}>({
		loading: false,
		dataSource: [],
		total: 0,
		current: 1,
	});
	const request = (params: { page: number }) => {
		setState((preState) => ({ ...preState, loading: true }));
		return Request.sendRequest({
			url: '/v1/device/dust_list',
			params,
		})
			.then((data: any) => {
				setState((preState) => ({
					...preState,
					...data,
					loading: false,
					dataSource: data.list,
				}));
			})
			.catch((error) => {
				setState((preState) => ({ ...preState, loading: false }));
				return Promise.reject(error);
			});
	};
	return { state, request } as const;
};
