import streamlit as st
import pandas as pd
import argparse
import datetime as dt
from sqlmodel import create_engine, Session

parser = argparse.ArgumentParser(description="A steamlit dashboard for visualising news analytics.")
parser.add_argument("--database", type=str, default="sqlite:///database.db")

class Dasboard:
    def __init__(self, database) -> None:
        self.engine = create_engine(database)
        self.attr = {
            "date_range": self.get_date_range(),
        }
        self.state = st.session_state
        self.build()


    def build(self):

        # ~~~ Build Sidebar ~~~~~~~~~
        st.sidebar.header("Newsreader")

        with st.form(key="date_picker"):
            st.sidebar.date_input(
                "Period From",
                key="period_from",
                min_value=self.attr["date_range"][0],
                max_value=self.attr["date_range"][1],
                value=self.attr["date_range"][0]
            )
            st.sidebar.date_input(
                "Period To",
                key="period_to",
                min_value=self.attr["date_range"][0],
                max_value=self.attr["date_range"][1],
                value=self.attr["date_range"][1]
            )

        # ~~~ Build Main UI ~~~~~~~~~~

        st.text_input("Search", key="search_text")

        st.write(self.state.search_text)
        st.write([self.state.period_from, self.state.period_to])
        st.write(self.get_total_sentiment("00375cd420e37d4084c6668975f91648"))


    # ~~~ Callbacks ~~~~~~~~~~~
        

    # ~~~ Analytics Operations ~~~~~~
    def exec(self, stmt: str, params = {}):
        with 