$(function () {
  function hideLeadFields() {
    // These labels should be hidden on "Add new lead"
    const hideLabels = [
      "Position",
      "Public",
      "Contacted Today",
      "Due Date",
      "Vehicle No",
      "Model",
      "Department",
      "Call Count",
      "Escalation Level",
      "Original Due Date",
      "L2 Start Date"
    ];

    // Keep only these custom labels (your required fields)
    const keepLabels = [
      "Address",
      "Vehicle Enquired",
      "Payment Mode",
      "When To Purchase"
    ];

    // Hide by label text (works for both default + custom fields)
    $(".form-group").each(function () {
      const $fg = $(this);
      const label = $.trim($fg.find("label").first().text().replace("*", ""));

      if (!label) return;

      // If it's one of the required ones, never hide
      if (keepLabels.includes(label)) return;

      // Hide unwanted ones
      if (hideLabels.includes(label)) {
        $fg.hide();
      }
    });
  }

  // Run once on page load
  hideLeadFields();

  // Also run when modal opens / ajax loads form
  $(document).on("shown.bs.modal ajaxComplete", function () {
    hideLeadFields();
  });
});
