<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/includes/layout.php';
crm_page_start('New Lead', 'operations', 'Operations / Lead Workspace');
?>
<form method="post" enctype="multipart/form-data" action="" novalidate>
    <input type="hidden" name="csrf_token" value="<?= crm_e(crm_csrf_token()) ?>">
    <section class="command-bar">
        <strong>Register New Lead</strong>
        <div class="form-actions">
            <a class="button secondary" href="<?= crm_e(crm_url('operations/leads.php')) ?>">Cancel</a>
            <button class="button secondary" type="submit" name="action" value="draft">Save Draft</button>
            <button class="button primary" type="submit" name="action" value="save"><i class="fa-solid fa-floppy-disk"></i> Save Lead</button>
        </div>
    </section>
    <div class="section-stack">
        <section class="card">
            <header class="card-head"><div class="card-title"><i class="fa-solid fa-circle-info"></i><div><h2>Lead Information</h2><p>Capture the source, priority and ownership of this opportunity.</p></div></div><span class="badge blue">Draft</span></header>
            <div class="card-body form-grid">
                <div class="field"><label for="lead_date">Lead Date <span class="required">*</span></label><input class="control" id="lead_date" name="lead_date" type="date" value="<?= date('Y-m-d') ?>" required></div>
                <div class="field"><label for="source">Lead Source <span class="required">*</span></label><select class="control" id="source" name="source_id" required><option value="">Select source</option><option>Website</option><option>Referral</option><option>Field Visit</option></select></div>
                <div class="field"><label for="priority">Priority <span class="required">*</span></label><select class="control" id="priority" name="priority"><option>Normal</option><option>High</option><option>Urgent</option></select></div>
                <div class="field"><label for="owner">Assigned To</label><select class="control" id="owner" name="owner_id"><option value="">Select team member</option></select></div>
                <div class="field wide"><label>Customer Type</label><div class="segmented"><label><input type="radio" name="customer_mode" value="existing" checked> Existing</label><label><input type="radio" name="customer_mode" value="new"> New Customer</label></div></div>
                <div class="field wide"><label for="company">Organization / Customer <span class="required">*</span></label><input class="control" id="company" name="company_name" placeholder="Search or enter organization name" autocomplete="off" required></div>
            </div>
        </section>

        <section class="card" data-new-customer hidden>
            <header class="card-head"><div class="card-title"><i class="fa-solid fa-building"></i><div><h2>Customer Profile</h2><p>Basic legal and location information for a new customer.</p></div></div></header>
            <div class="card-body form-grid">
                <div class="field"><label for="gst">GST Number</label><input class="control" id="gst" name="gst_no" maxlength="15" placeholder="27ABCDE1234F1Z5"></div>
                <div class="field"><label for="state">State</label><select class="control" id="state" name="state_id"><option value="">Select state</option></select></div>
                <div class="field"><label for="district">District</label><select class="control" id="district" name="district_id"><option value="">Select district</option></select></div>
                <div class="field"><label for="taluka">Taluka / City</label><select class="control" id="taluka" name="taluka_id"><option value="">Select taluka</option></select></div>
                <div class="field full"><label for="address">Address</label><textarea class="control textarea" id="address" name="address" placeholder="Complete business address"></textarea></div>
            </div>
        </section>

        <section class="card">
            <header class="card-head"><div class="card-title"><i class="fa-solid fa-address-card"></i><div><h2>Contact Details</h2><p>Primary person responsible for this enquiry.</p></div></div></header>
            <div class="card-body form-grid">
                <div class="field"><label for="contact_name">Contact Person <span class="required">*</span></label><input class="control" id="contact_name" name="contact_name" placeholder="Full name" required></div>
                <div class="field"><label for="designation">Designation</label><input class="control" id="designation" name="designation" placeholder="Job title"></div>
                <div class="field"><label for="mobile">Mobile Number <span class="required">*</span></label><input class="control" id="mobile" name="mobile" inputmode="numeric" maxlength="10" placeholder="10 digit number" required></div>
                <div class="field"><label for="email">Email Address</label><input class="control" id="email" name="email" type="email" placeholder="name@company.com"></div>
                <div class="field"><label for="office_phone">Office Contact</label><input class="control" id="office_phone" name="office_phone" placeholder="Office number"></div>
                <div class="field"><label for="visiting_card">Visiting Card</label><input class="control" id="visiting_card" name="visiting_card" type="file" accept="image/jpeg,image/png,application/pdf"></div>
            </div>
        </section>

        <section class="card">
            <header class="card-head"><div class="card-title"><i class="fa-solid fa-boxes-stacked"></i><div><h2>Product Interest</h2><p>Add products discussed with the customer.</p></div></div><button class="button secondary small" type="button" data-add-product><i class="fa-solid fa-plus"></i> Add Product</button></header>
            <div class="table-wrap"><table class="data-table"><thead><tr><th>Product</th><th>Quantity</th><th>Rate</th><th>Tax %</th><th></th></tr></thead><tbody data-products-body><tr class="empty-row"><td colspan="5"><i class="fa-solid fa-box-open"></i> No products added yet</td></tr></tbody></table></div>
        </section>

        <section class="card">
            <header class="card-head"><div class="card-title"><i class="fa-solid fa-calendar-check"></i><div><h2>Follow-up Plan</h2><p>Record this interaction and schedule the next action.</p></div></div></header>
            <div class="card-body form-grid">
                <div class="field"><label for="nature">Nature</label><select class="control" id="nature" name="nature_id"><option value="">Select nature</option><option>Hot</option><option>Warm</option><option>Cold</option></select></div>
                <div class="field"><label for="status">Status <span class="required">*</span></label><select class="control" id="status" name="status_id" required><option value="">Select status</option><option>Open</option><option>Follow-up</option><option>Converted</option><option>Lost</option></select></div>
                <div class="field"><label for="next_followup">Next Follow-up</label><input class="control" id="next_followup" name="next_followup" type="datetime-local"></div>
                <div class="field"><label for="category">Category</label><select class="control" id="category" name="category_id"><option value="">Select category</option></select></div>
                <div class="field full"><label for="conversation">Conversation / Notes <span class="required">*</span></label><textarea class="control textarea" id="conversation" name="conversation" placeholder="Summarize the discussion, requirements and commitments" required></textarea></div>
                <div class="field wide"><label for="purchase_order">Purchase Order</label><input class="control" id="purchase_order" name="purchase_order" type="file" accept="image/jpeg,image/png,application/pdf"></div>
                <div class="field wide"><label><span>Quotation</span></label><label class="segmented"><input type="checkbox" name="generate_quotation" value="1"> Generate quotation after saving</label></div>
            </div>
        </section>
    </div>
</form>
<?php crm_page_end(); ?>
