from flask import Flask

def create_app():
    app = Flask(__name__)

    # Register blueprints
    from blueprints.auth_bp import auth_bp
    app.register_blueprint(auth_bp)

    from blueprints.config_bp import config_bp
    app.register_blueprint(config_bp)

    from blueprints.inventory_bp import inventory_bp
    app.register_blueprint(inventory_bp)

    from blueprints.catalog_bp import catalog_bp
    app.register_blueprint(catalog_bp)

    from blueprints.pos_bp import pos_bp
    app.register_blueprint(pos_bp)

    from blueprints.customers_bp import customers_bp
    app.register_blueprint(customers_bp)

    from blueprints.cashregister_bp import cashregister_bp
    app.register_blueprint(cashregister_bp)

    from blueprints.invoicing_bp import invoicing_bp
    app.register_blueprint(invoicing_bp)

    from blueprints.accounting_bp import accounting_bp
    app.register_blueprint(accounting_bp)

    # Health check
    @app.route('/pos/health')
    def health():
        return {'status': 'ok'}

    from flask import render_template, send_from_directory

    @app.route('/pos/login')
    def pos_login():
        return render_template('login.html')

    @app.route('/pos/catalog')
    def pos_catalog():
        return render_template('catalog.html')

    @app.route('/pos/inventory')
    def pos_inventory():
        return render_template('inventory.html')

    @app.route('/pos/sale')
    def pos_sale():
        return render_template('pos.html')

    @app.route('/pos/customers')
    def pos_customers():
        return render_template('customers.html')

    @app.route('/pos/invoicing')
    def pos_invoicing():
        return render_template('invoicing.html')

    @app.route('/pos/accounting')
    def pos_accounting():
        return render_template('accounting.html')

    @app.route('/pos/dashboard')
    def pos_dashboard():
        return render_template('dashboard.html')

    @app.route('/pos/config')
    def pos_config():
        return render_template('config.html')

    @app.route('/pos/reports')
    def pos_reports():
        return render_template('reports.html')

    @app.route('/pos/static/<path:filename>')
    def pos_static(filename):
        return send_from_directory('static', filename)

    return app

if __name__ == '__main__':
    app = create_app()
    app.run(host='0.0.0.0', port=5001, debug=True)
