use advanced::{layout, renderer::{Quad, Style}, Layout, Widget};
use advanced::widget::Tree;
use iced::*;

pub struct ItemPreview;

impl<Message, Renderer> Widget<Message, Theme, Renderer> for ItemPreview
where
    Renderer: iced::advanced::Renderer,
{
    fn size(&self) -> Size<Length> {
        Size {
            width: Length::Shrink,
            height: Length::Shrink,
        }
    }
    fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, _limits: &layout::Limits) -> layout::Node {
        layout::Node::new([100, 100].into())
    }
    fn draw(
        &self,
        _state: &Tree,
        renderer: &mut Renderer,
        _theme: &Theme,
        _style: &Style,
        layout: Layout<'_>,
        _cursor: mouse::Cursor,
        _viewport: &Rectangle,
    ) {
        renderer.fill_quad(
            Quad {
                bounds: layout.bounds(),
                border: Border {
                    color: Color::from_rgb(0.6, 0.8, 1.0),
                    width: 1.0,
                    radius: 10.0.into(),
                },
                shadow: Shadow::default(),
            },
            Color::from_rgb(0.0, 0.2, 0.4),
        );
        }
    }

impl<'a,Message,Renderer> From<ItemPreview> for Element<'a, Message, Theme, Renderer>
where
    Renderer: iced::advanced::Renderer,
    {
        fn from(widget: ItemPreview) -> Self{
            Self::new(widget)           
        }
    }