// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use super::*;
use crate::layout::spacer::spacer;
use crate::types::Length;

#[ test ]
fn default_no_background()
{
	let c = container::<()>( spacer() );
	assert!( c.background.is_none() );
}

#[ test ]
fn padding_sets_all_four_sides()
{
	let c = container::<()>( spacer() ).padding( 10.0 );
	assert_eq!( c.pad_top,    Length::px( 10.0 ) );
	assert_eq!( c.pad_right,  Length::px( 10.0 ) );
	assert_eq!( c.pad_bottom, Length::px( 10.0 ) );
	assert_eq!( c.pad_left,   Length::px( 10.0 ) );
}

#[ test ]
fn padding_h_only_touches_left_and_right()
{
	let c = container::<()>( spacer() ).padding_h( 8.0 );
	assert_eq!( c.pad_left,  Length::px( 8.0 ) );
	assert_eq!( c.pad_right, Length::px( 8.0 ) );
	assert_eq!( c.pad_top,    Length::px( 0.0 ) );
	assert_eq!( c.pad_bottom, Length::px( 0.0 ) );
}

#[ test ]
fn padding_v_only_touches_top_and_bottom()
{
	let c = container::<()>( spacer() ).padding_v( 6.0 );
	assert_eq!( c.pad_top,    Length::px( 6.0 ) );
	assert_eq!( c.pad_bottom, Length::px( 6.0 ) );
	assert_eq!( c.pad_left,  Length::px( 0.0 ) );
	assert_eq!( c.pad_right, Length::px( 0.0 ) );
}

#[ test ]
fn per_edge_overrides_uniform_padding()
{
	// Idiomatic "uniform with one override".
	let c = container::<()>( spacer() )
		.padding( 12.0 )
		.padding_bottom( 22.0 );
	assert_eq!( c.pad_top,    Length::px( 12.0 ) );
	assert_eq!( c.pad_right,  Length::px( 12.0 ) );
	assert_eq!( c.pad_bottom, Length::px( 22.0 ) );
	assert_eq!( c.pad_left,   Length::px( 12.0 ) );
}

#[ test ]
fn background_set()
{
	use crate::types::Color;
	let c = container::<()>( spacer() ).background( Color::BLACK );
	assert!( c.background.is_some() );
}

#[ test ]
fn radius_set_uniform()
{
	let c = container::<()>( spacer() ).radius( 12.0 );
	assert_eq!( c.corners, Corners::all( 12.0 ) );
}

#[ test ]
fn radius_set_per_corner()
{
	let c = container::<()>( spacer() ).radius( Corners::top( 16.0 ) );
	assert_eq!( c.corners.tl, 16.0 );
	assert_eq!( c.corners.tr, 16.0 );
	assert_eq!( c.corners.br, 0.0 );
	assert_eq!( c.corners.bl, 0.0 );
}

#[ test ]
fn radius_set_tuple()
{
	let c = container::<()>( spacer() ).radius( ( 8.0, 4.0, 2.0, 1.0 ) );
	assert_eq!( c.corners.tl, 8.0 );
	assert_eq!( c.corners.tr, 4.0 );
	assert_eq!( c.corners.br, 2.0 );
	assert_eq!( c.corners.bl, 1.0 );
}

#[ test ]
fn default_no_surface()
{
	let c = container::<()>( spacer() );
	assert!( c.surface.is_none() );
}

#[ test ]
fn surface_stores_slot_id()
{
	let c = container::<()>( spacer() ).surface( "surface-card" );
	assert_eq!( c.surface.as_deref(), Some( "surface-card" ) );
}

#[ test ]
fn max_width_caps_preferred_width()
{
	use crate::render::Canvas;
	let canvas = Canvas::new( 800, 600 );
	let c = container::<()>( spacer() ).max_width( 200.0 );
	let ( w, _ ) = c.preferred_size( 800.0, &canvas );
	assert!( w <= 200.0 );
}
