import TextField from "@mui/material/TextField";
import { AdminFormDialog, AdminFormFieldGrid, AdminFormSection } from "@/shared/ui/AdminFormDialog.jsx";
import { AdminUserIdentity } from "@/shared/ui/AdminUserIdentity.jsx";

export function ExternalAdminUserPasswordDialog({
    abilities,
    form,
    loading,
    onClose,
    onFormChange,
    onSubmit,
    user,
}) {
    return (
        <AdminFormDialog
            disabled={!abilities.canResetPassword}
            loading={loading}
            open={Boolean(user)}
            size="compact"
            submitLabel="重置密码"
            title="重置外管密码"
            onClose={onClose}
            onSubmit={onSubmit}
        >
            <AdminFormSection title="外管用户">
                <AdminUserIdentity
                    rows={[user?.linkedUser?.displayUserId, user?.linkedUser?.userId]}
                    user={user?.linkedUser}
                />
            </AdminFormSection>
            <AdminFormSection title="新密码">
                <AdminFormFieldGrid columns="repeat(2, minmax(0, 1fr))">
                    <TextField
                        autoComplete="new-password"
                        disabled={!abilities.canResetPassword || loading}
                        label="密码"
                        required
                        type="password"
                        value={form.password}
                        onChange={(event) => onFormChange({ password: event.target.value })}
                    />
                    <TextField
                        autoComplete="new-password"
                        disabled={!abilities.canResetPassword || loading}
                        label="确认密码"
                        required
                        type="password"
                        value={form.confirmPassword}
                        onChange={(event) => onFormChange({ confirmPassword: event.target.value })}
                    />
                </AdminFormFieldGrid>
            </AdminFormSection>
        </AdminFormDialog>
    );
}
