import { PHXSelectWithAction } from '../SelectWithAction';
import { useGetUserTarget } from './hooks/UseGetUserTarget';
import React, { useEffect, useState } from 'react';
export const PHXUserTargetSelect = ({ value, onChange, error, label = 'Tệp đối tượng', helpText = 'Chọn danh sách đối tượng mà bạn muốn gửi thông báo của chiến dịch', }) => {
    const { listUserTarget, loading: userTargetLoading, searchQuery, handleFilter } = useGetUserTarget();
    const [baseUrl, setBaseUrl] = useState('');
    useEffect(() => {
        setBaseUrl(window.location.origin);
    }, []);
    const targetOptions = listUserTarget.map((item) => {
        var _a;
        return ({
            value: item.id.toString(),
            label: item.name,
            helpText: ((_a = item.school_year) === null || _a === void 0 ? void 0 : _a.name) || '',
            action: {
                type: 'edit',
                onClick: (val) => {
                    window.open(`${baseUrl}/user-segment/manage/edit/${val}`, '_blank');
                },
            },
        });
    });
    return (React.createElement(PHXSelectWithAction, { addNew: {
            title: 'Thêm mới',
            onClick: () => window.open(`${baseUrl}/user-segment/manage/add`, '_blank'),
        }, error: error, helpText: helpText, label: label, loading: userTargetLoading, onChange: onChange, options: targetOptions, search: { value: searchQuery, handleFilter }, value: value }));
};
//# sourceMappingURL=UsertargetSelect.js.map