"""DataTools Quality Check — stub page."""

from __future__ import annotations

import sys
from pathlib import Path

import streamlit as st

_project_root = Path(__file__).resolve().parent.parent.parent.parent
if str(_project_root) not in sys.path:
    sys.path.insert(0, str(_project_root))

from src.gui.components import (
    back_to_home_link,
    render_sticky_footer,
    render_tool_header,
    hide_streamlit_chrome,
    require_feature_or_render_upgrade,
)
from src.license import FeatureFlag

hide_streamlit_chrome()
render_sticky_footer()
back_to_home_link()
from src.audit import log_page_open
log_page_open("8_Validator_Reporter")
require_feature_or_render_upgrade(FeatureFlag.VALIDATOR_REPORTER)

# ---------------------------------------------------------------------------
# Header
# ---------------------------------------------------------------------------

render_tool_header("08_validator_reporter")

st.info("This tool is under development.")

# ---------------------------------------------------------------------------
# What this tool will do
# ---------------------------------------------------------------------------

st.markdown("""
**Features:**
- Column-level validation rules (not null, unique, regex pattern, range, enum)
- Cross-column validation (e.g., start_date < end_date)
- Data quality score per column and overall
- Generate PDF quality report
- Generate Excel report with flagged rows highlighted
- Summary dashboard: pass/fail counts, severity breakdown
""")

st.divider()

# ---------------------------------------------------------------------------
# File upload (functional)
# ---------------------------------------------------------------------------

uploaded = st.file_uploader(
    "Import CSV or Excel file",
    type=["csv", "tsv", "xlsx", "xls"],
    help="Import a file to preview. Processing is not yet available.",
    key="validator_file_upload",
)

if uploaded is not None:
    import pandas as pd
    try:
        if uploaded.name.endswith((".xlsx", ".xls")):
            df = pd.read_excel(uploaded)
        else:
            df = pd.read_csv(uploaded)
        st.subheader(f"Preview: {uploaded.name}")
        st.caption(f"{len(df)} rows, {len(df.columns)} columns")
        st.dataframe(df.head(10), width="stretch")
    except Exception as e:
        from src.core.errors import format_for_user
        st.error(
            f"**Could not read `{uploaded.name}`**\n\n"
            f"```\n{format_for_user(e)}\n```"
        )

# ---------------------------------------------------------------------------
# Placeholder options
# ---------------------------------------------------------------------------

st.subheader("Validation Rules")

st.file_uploader("Load rules file (JSON)", type=["json"], disabled=True, key="validator_rules")
st.multiselect("Quick checks", [
    "No null values",
    "No duplicate rows",
    "All emails valid",
    "All dates parseable",
    "Numeric columns in range",
], disabled=True)

st.subheader("Report Format")

st.selectbox("Output format", ["Excel (flagged rows)", "PDF summary", "Both"], disabled=True)

st.divider()
st.button("Validate & Generate Report", type="primary", width="stretch", disabled=True)

