from flask import render_template

TEMPLATE = 'components/modul_sto_sammler.html'

def get_formular_html():
    return render_template(TEMPLATE)

def berechne(form_data):
    pos = []
    liste = form_data.get('sto_liste', '').strip()
    if liste:
        lines = [l.strip() for l in liste.split('\n') if l.strip()]
        for i, line in enumerate(lines):
            pos.append(dict(pos_nr='10038100', kurztext=f'Störung: {line}', menge=1, einheit='ST'))
    return pos

def _float(val, default=0):
    try: return float(str(val).replace(',', '.'))
    except: return default

def _int(val, default=0):
    try: return int(float(str(val).replace(',', '.')))
    except: return default
