<?php
$commonFields = [
    [
        ":::Aneurysm repair|Appendectomy|Back surgery|Bariatric surgery/gastric bypass|Bilateral tubal ligation|Breast resection/mastectomy|CABG|Carotid endarterectomy/stent|Carpal tunnel release surgery",
    ],
    [
        ":::Cataract/lens surgery|Cesarean section|Cholecystectomy/bile duct surgery|Dilation and curettage|Hemorrhoid surgery|Hip arthroplasty|Hip replacement|Hysterectomy|Inguinal hernia repair",
    ],
    [
        ":::Knee arthroplasty|LASIK|Laminectomy|Nasal surgery|PTCA/PCI|Pacemaker/defibrillator|Prostate surgery|Prostatectomy|Rotator cuff surgery",
    ],
    [
        ":::Sinus surgery|Skin cancer excision|Spinal fusion|TAH-BSO|TURP|Tonsillectomy/Adenoidectomy|Vasectomy",
    ]
];

$customFields = [
    [
        ":::Bladder surgery/repair post s|Cardiac catheterization|Cardiac Stent Placement",
    ],
    [
        ":::IVC filter/stent|Knee Replacement|Lumpectomy",
    ],
    [
        ":::Multiple heart stents|Oral surgery|Rt elbow ulnar repair",
    ],
    [
        ":::Rt Nephrectomy|Thyroidectomy|Valve replacement with stent",
    ]
];

for ($i = 0; $i < count($commonFields); $i++) {
    for($j = 0; $j < count($commonFields[$i]); $j++) {
        $parts = explode(":::", $commonFields[$i][$j]);
        $head = 'common';
        if(!empty($parts[0])) $head = $parts[0];
        $values = explode("|", $parts[1]);
        for($k = 0; $k < count($values); $k++) {
            $fName = $head . '_' . sanitize_field_name($values[$k]);
            if(isset($newContentData[$fName])) { ?>
                <div>
                    <?= ucwords($head) ?>
                    <i class="fa fa-arrow-right text-sm text-secondary"></i>
                    <span class="font-weight-bold"><?= $values[$k] ?></span>
                </div>
            <?php }
        }
    }
}

for ($i = 0; $i < count($customFields); $i++) {
    for($j = 0; $j < count($customFields[$i]); $j++) {
        $parts = explode(":::", $customFields[$i][$j]);
        $head = 'custom';
        if(!empty($parts[0])) $head = $parts[0];
        $values = explode("|", $parts[1]);
        for($k = 0; $k < count($values); $k++) {
            $fName = $head . '_' . sanitize_field_name($values[$k]);
            if(isset($newContentData[$fName])) { ?>
                <div>
                    <?= ucwords($head) ?>
                    <i class="fa fa-arrow-right text-sm text-secondary"></i>
                    <span class="font-weight-bold"><?= $values[$k] ?></span>
                </div>
            <?php }
        }
    }
}

if(isset($newContentData['comments'])) { ?>
    <div class="mt-2 mb-1">
        <div class="font-weight-bold">Comments:</div>
        <div><?= $newContentData['comments'] ?></div>
    </div>
<?php }
