"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PHXUserTargetSelect = void 0;
const tslib_1 = require("tslib");
const SelectWithAction_1 = require("../SelectWithAction");
const UseGetUserTarget_1 = require("./hooks/UseGetUserTarget");
const react_1 = tslib_1.__importStar(require("react"));
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 } = (0, UseGetUserTarget_1.useGetUserTarget)();
    const [baseUrl, setBaseUrl] = (0, react_1.useState)('');
    (0, react_1.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_1.default.createElement(SelectWithAction_1.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 }));
};
exports.PHXUserTargetSelect = PHXUserTargetSelect;
//# sourceMappingURL=UsertargetSelect.js.map