<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{fragments/layout :: head('Vendor Form')}"></head>
<body>
<nav th:replace="~{fragments/layout :: adminbar}"></nav>

<section>
    <div class="container">
        <div class="form-card" style="max-width:680px">
            <h2 th:text="${vendor.id == null} ? 'Add Vendor' : 'Edit Vendor'">Add Vendor</h2>
            <p class="subtitle">Profile, settlement details &amp; commission</p>

            <form th:action="@{/admin/vendors}" th:object="${vendor}" method="post">
                <input type="hidden" th:field="*{id}"/>

                <div class="form-grid2">
                    <div class="form-group field">
                        <label>Name</label>
                        <input type="text" th:field="*{name}" required/>
                        <small class="err" th:if="${#fields.hasErrors('name')}" th:errors="*{name}"></small>
                    </div>
                    <div class="form-group field">
                        <label>Contact Person</label>
                        <input type="text" th:field="*{contactPerson}"/>
                    </div>
                    <div class="form-group field">
                        <label>Phone</label>
                        <input type="tel" th:field="*{phone}"/>
                    </div>
                    <div class="form-group field">
                        <label>Email</label>
                        <input type="email" th:field="*{email}"/>
                        <small class="err" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></small>
                    </div>
                    <div class="form-group field">
                        <label>GST Number</label>
                        <input type="text" th:field="*{gstNumber}"/>
                    </div>
                    <div class="form-group field">
                        <label>Commission % (blank = global default)</label>
                        <input type="number" step="0.01" th:field="*{commissionPercent}" placeholder="e.g. 15"/>
                    </div>
                    <div class="form-group field" style="grid-column:1 / -1">
                        <label>Address</label>
                        <input type="text" th:field="*{address}"/>
                    </div>
                    <div class="form-group field" style="grid-column:1 / -1">
                        <label>Settlement / Bank Details</label>
                        <input type="text" th:field="*{settlementDetails}" placeholder="Account no, IFSC, UPI…"/>
                    </div>
                    <div class="form-group" style="grid-column:1 / -1">
                        <label style="font-weight:500;color:#444">
                            <input type="checkbox" th:field="*{active}"/> Active
                        </label>
                    </div>
                </div>

                <button class="btn btn-primary" type="submit" style="width:100%">Save Vendor</button>
                <a class="btn btn-ghost" th:href="@{/admin/vendors}" style="display:block;margin-top:8px;text-align:center">Cancel</a>
            </form>
        </div>
    </div>
</section>

<footer th:replace="~{fragments/layout :: footer}"></footer>
</body>
</html>
