I'm confused with something regarding the rigorous mathematical definition of an arbitrary operator in the position/momentum basis and how it connects to the phase-space representation (https://en.wikipedia.org/wiki/Wigner%E2%80%93Weyl_transform, https://en.wikipedia.org/wiki/Wigner_quasiprobability_distribution#:~:text=The%20Wigner%20function%20W(x,p)%20with%20the%20Wigner%20function).
In a lot of quantum mechancis textbooks the quantum average of an operator $\hat A$ for a state vector $|\psi(t)>$ is usually expressed in the position basis (and likewise in the momentum basis) at time $t$ as
$<\psi(t) | \hat A | \psi(t) > = \int_{\mathbb R}dx\psi(x,t)^*\hat A \psi(x,t)$.
This definition fails to satisfy me because it appears to confuse the operators that act on state vectors like $|\psi(t)>$ of the Hilbert space $\mathcal H$ and operators acting on square-integrable function like $\psi(x,t)$. It would make more sense to me, as discussed in Schrödinger equation in position representation if instead we had
$<\psi(t) | \hat A | \psi(t) > = \iint_{\mathbb R^2}dxdy\psi(x)\psi^*(x,t)A(x,y)\psi(y,t)$
with then $A(x,y) = <x|\hat A|y>$ as it would for any other discrete basis.
Now this confuses me because most textbooks I came across that dealt with this (for instance the COHEN-TANNOUDJI) seem to prefer to write the operator $\hat A$ as $\hat A(\hat x)$ arguing that it implies that
$<x|\hat A(\hat x) | \psi(t)> = A(x)\psi(x,t)$
which I intuitively understand because said operator and the position operator $\hat x$ share the position basis as an eigenbasis.
However, in the phase-space formulation of quantum mechanics, objects like $A(x,p)$ and $<x|\hat A | y>$ exist and I can't make sense of the two together with $A(\hat x)$.
Could anyone enlighten me? Can all operators be written in terms of the canonical variables $x$ and $p$? does it make sense to talk about the matrix element $<x|\hat A|y>$? what about $<x|\hat A(\hat x, \hat p) | y>$? Is the standard textbook quantum average legitimate once the matrix is diagonal in the position/momentum basis?
Here is the Quantum mechanics I textbook from Cohen-Tannoudji (the French version but it should be self-explanatory).