use crate::model::control::Control;
use crate::model::paragraph::{LineSeg, Paragraph};
use crate::model::shape::{TextWrap, VertAlign, VertRelTo};
use crate::model::table::{Table, TablePageBreak};
pub(crate) fn stored_hwpx_cut_owns_outer_frame(
original_stored_frame: bool,
host: &Paragraph,
table: &Table,
) -> bool {
let [line] = host.line_segs.as_slice() else {
return false;
};
original_stored_frame
&& !table.common.treat_as_char
&& table.common.flow_with_text
&& table.common.text_wrap == TextWrap::TopAndBottom
&& table.common.vert_rel_to == VertRelTo::Para
&& table.common.vert_align == VertAlign::Top
&& table.layout_page_break() == TablePageBreak::RowBreak
&& host.text.trim().is_empty()
&& !host.stored_text_partition_is_dirty()
&& !host.cell_format_vpos_dirty
&& line.tag & LineSeg::TAG_IMPLEMENTATION_PROPERTY == 0
&& line.vertical_pos >= 0
&& line.line_height > 0
&& u32::try_from(line.line_height).is_ok_and(|height| height < table.common.height)
&& table.common.height <= i32::MAX as u32
&& host
.controls
.iter()
.filter(|c| matches!(c, Control::Table(_)))
.count()
== 1
&& host.controls.iter().all(|control| {
matches!(
control,
Control::Table(_)
| Control::SectionDef(_)
| Control::ColumnDef(_)
| Control::PageNumberPos(_)
)
})
&& table.cells.iter().all(|cell| !cell.dirty_flag)
}