<?php
if (!defined('ABSPATH')) exit;
$admin_test=!empty($admin_test);
$service_scope=in_array($s['service_scope']??'both',['interior','exterior','both'],true)?$s['service_scope']:'both';
$both_services=$service_scope==='both';
$total_steps=$both_services?6:5;
$step_label=static function($internal_step)use($both_services,$total_steps){return 'Step '.($both_services?$internal_step:$internal_step-1).' of '.$total_steps;};
$additional_services=['wallpaper'=>'Wallpaper removal','popcorn'=>'Popcorn ceiling removal','cabinets'=>'Cabinet painting'];
$conditions_to_review=['water_damage'=>'Water damage','plaster'=>'Extensive plaster repair','new_drywall'=>'New drywall','old_trim'=>'Older glossy trim'];
$exterior_services=['ext_stripping'=>'Paint or finish stripping','ext_trim'=>'Trim, fascia and soffit painting','ext_shutters'=>'Shutter painting','ext_porches'=>'Porch, railing or column painting','ext_foundation'=>'Foundation painting','ext_staining'=>'Deck or fence staining'];
$exterior_conditions=['ext_peeling'=>'Peeling or flaking paint','ext_bare'=>'Bare wood or exposed substrate','ext_rot'=>'Rot or damaged siding','ext_mildew'=>'Mildew or algae','ext_rust'=>'Rust on metal surfaces','ext_caulking'=>'Failed caulking','ext_lead'=>'Possible lead-based paint','ext_access'=>'Difficult landscaping or restricted access'];
$enabled_specialties=is_array($s['specialty_options']??null)?$s['specialty_options']:[];
$additional_services=array_filter($additional_services,static function($key)use($enabled_specialties){return !empty($enabled_specialties[$key]);},ARRAY_FILTER_USE_KEY);
$conditions_to_review=array_filter($conditions_to_review,static function($key)use($enabled_specialties){return !empty($enabled_specialties[$key]);},ARRAY_FILTER_USE_KEY);
$exterior_services=array_filter($exterior_services,static function($key)use($enabled_specialties){return !empty($enabled_specialties[$key]);},ARRAY_FILTER_USE_KEY);
$exterior_conditions=array_filter($exterior_conditions,static function($key)use($enabled_specialties){return !empty($enabled_specialties[$key]);},ARRAY_FILTER_USE_KEY);
?>
<div class="pcec" data-pcec<?php if($s['accent_color']): ?> style="--pcec-accent:<?php echo esc_attr($s['accent_color']); ?>"<?php endif; ?>>
<script type="application/json" class="pcec__config"><?php echo wp_json_encode($config); ?></script>
<form class="pcec__form" novalidate>
<header class="pcec__header"><h2><?php echo $admin_test?'Internal Test Estimate':'Painting Cost Estimator'; ?></h2><p>Answer a few straightforward questions for a ballpark project range.</p></header>
<div class="pcec__progress" aria-hidden="true"><?php for($i=0;$i<$total_steps;$i++): ?><span<?php echo $i===0?' class="is-active"':''; ?>></span><?php endfor; ?></div>

<?php if($both_services): ?><section class="pcec__step is-active" data-step="1"><p class="pcec__question-number"><?php echo esc_html($step_label(1)); ?></p><h3>What would you like painted?</h3>
<div class="pcec__choice-grid"><label><input type="radio" name="project_type" value="interior"><span><b>Interior</b><small>Rooms, walls, ceilings, trim and doors</small></span></label><label><input type="radio" name="project_type" value="exterior"><span><b>Exterior</b><small>Siding, trim and exterior doors</small></span></label></div>
<p class="pcec__validation" role="alert"></p><div class="pcec__actions"><button type="button" class="pcec__next">Continue</button></div></section><?php endif; ?>

<?php if($service_scope!=='exterior'): ?><section class="pcec__step pcec__interior<?php echo $both_services?'':' is-active'; ?>" data-step="2"><p class="pcec__question-number"><?php echo esc_html($step_label(2)); ?></p><h3>Add the rooms being painted</h3><p class="pcec__hint">Use the room dimensions. We convert them into approximate wall, ceiling and trim measurements.</p>
<div class="pcec__rooms"><div class="pcec__room-head"><span>Room name</span><span>Length</span><span>Width</span><span>Height</span><span>Type</span><span>Accent wall</span><span></span></div><div data-rooms></div></div>
<button type="button" class="pcec__add-room">+ Add Another Room</button><p class="pcec__room-summary" data-room-summary></p>
<label class="pcec__field pcec__stairwell"><span>Stairwell</span><select name="stairwell"><option value="none">None</option><option value="one">Standard one-storey stairwell</option><option value="two">High or two-storey stairwell</option></select><small>Include stairwell walls that are part of this project.</small></label>
<p class="pcec__validation" role="alert"></p><div class="pcec__actions"><?php if($both_services): ?><button type="button" class="pcec__back">Back</button><?php endif; ?><button type="button" class="pcec__next">Continue</button></div></section><?php endif; ?>

<?php if($service_scope!=='interior'): ?><section class="pcec__step pcec__exterior<?php echo $both_services?'':' is-active'; ?>" data-step="2"><p class="pcec__question-number"><?php echo esc_html($step_label(2)); ?></p><h3>Tell us about the home exterior</h3><div class="pcec__grid pcec__grid--2">
<label class="pcec__field"><span>Approximate above-grade home size (sq. ft.)</span><input type="number" name="exterior_area" min="100" max="20000" placeholder="1800"></label>
<label class="pcec__field"><span>Number of storeys</span><select name="exterior_storeys"><option value="one">One</option><option value="two" selected>Two</option><option value="three">Three or more</option></select></label>
<label class="pcec__field"><span>Main exterior surface</span><select name="exterior_surface"><option value="vinyl_metal">Vinyl or metal siding</option><option value="wood">Wood siding</option><option value="stucco">Stucco</option><option value="brick">Brick or masonry</option><option value="other">Other / mixed</option></select></label>
<label class="pcec__field"><span>Site access</span><select name="exterior_access"><option value="easy">Easy access</option><option value="limited">Some restricted areas</option><option value="difficult">Difficult access or steep grade</option></select></label></div><p class="pcec__validation" role="alert"></p><div class="pcec__actions"><?php if($both_services): ?><button type="button" class="pcec__back">Back</button><?php endif; ?><button type="button" class="pcec__next">Continue</button></div></section><?php endif; ?>

<section class="pcec__step" data-step="3"><p class="pcec__question-number"><?php echo esc_html($step_label(3)); ?></p><h3>What should the estimate include?</h3>
<div class="pcec__interior pcec__option-list"><label><input type="checkbox" name="walls" checked><span><b>Walls</b><small>Two finish coats and standard preparation.</small></span></label><label><input type="checkbox" name="ceilings"><span><b>Ceilings</b></span></label><label><input type="checkbox" name="trim"><span><b>Additional painted woodwork</b><small>Baseboards, casings, crown moulding or interior doors.</small></span></label></div>
<div class="pcec__interior pcec__woodwork" data-trim-options hidden><h4>Additional painted woodwork</h4><p class="pcec__hint">Select every surface that should be included. Door casing and door slab painting are priced separately.</p><div class="pcec__woodwork-table" role="group" aria-label="Additional painted woodwork">
<div class="pcec__woodwork-head"><span>Include</span><span>Surface</span><span>Quantity</span><span>What is included</span></div>
<label class="pcec__woodwork-row"><span><input type="checkbox" name="baseboards" checked></span><b>Baseboards</b><span class="pcec__auto-measure">Calculated from room dimensions</span><small>Baseboards around the entered rooms.</small></label>
<label class="pcec__woodwork-row"><span><input type="checkbox" name="door_casings"></span><b>Door frames and casings</b><span><input type="number" name="doors" min="0" max="50" value="0" aria-label="Door openings"></span><small>Enter the number of door openings. Door slabs are not included.</small></label>
<label class="pcec__woodwork-row"><span><input type="checkbox" name="window_casings"></span><b>Window casings</b><span><input type="number" name="windows" min="0" max="100" value="0" aria-label="Windows"></span><small>Enter the number of windows with painted surrounding trim.</small></label>
<label class="pcec__woodwork-row"><span><input type="checkbox" name="crown"></span><b>Crown moulding</b><span><input type="number" name="crown_length" min="0" max="5000" value="0" aria-label="Crown moulding linear feet"></span><small>Enter the approximate linear feet of crown or decorative moulding.</small></label>
<label class="pcec__woodwork-row"><span><input type="checkbox" name="door_slabs"></span><b>Interior door slabs</b><span><input type="number" name="interior_doors" min="0" max="50" value="0" aria-label="Interior doors"></span><small>Standard interior doors painted on both sides. Frames and casings are separate.</small></label>
</div></div>
<div class="pcec__exterior pcec__grid pcec__grid--2"><label class="pcec__field"><span>Exterior doors</span><input type="number" name="exterior_doors" min="0" max="20" value="1"></label><label class="pcec__field"><span>Garage doors</span><input type="number" name="garage_doors" min="0" max="10" value="0"></label></div>
<p class="pcec__validation" role="alert"></p><div class="pcec__actions"><button type="button" class="pcec__back">Back</button><button type="button" class="pcec__next">Continue</button></div></section>

<section class="pcec__step" data-step="4"><p class="pcec__question-number"><?php echo esc_html($step_label(4)); ?></p><h3>What is the average condition?</h3><div class="pcec__choice-list">
<label><input type="radio" name="condition" value="good"><span><b>Good condition</b><small>Occasional nail holes or minor marks.</small></span></label><label><input type="radio" name="condition" value="normal" checked><span><b>Normal wear and repairs</b><small>Several holes, dents, small cracks or areas needing sanding.</small></span></label><label><input type="radio" name="condition" value="significant"><span><b>Significant preparation</b><small>Widespread damage, peeling, stains, plaster cracks or rough previous work.</small></span></label></div>
<div class="pcec__actions"><button type="button" class="pcec__back">Back</button><button type="button" class="pcec__next">Continue</button></div></section>

<section class="pcec__step" data-step="5"><p class="pcec__question-number"><?php echo esc_html($step_label(5)); ?></p><h3 class="pcec__interior">Add colour and work-space details</h3><h3 class="pcec__exterior">Add exterior colour and service details</h3>
<div class="pcec__interior pcec__grid pcec__grid--2"><label class="pcec__field"><span>Paint Colours</span><select name="colours"><option value="one">One colour throughout</option><option value="two_three">Two or three colours</option><option value="four_plus">Four or more colours</option><option value="undecided">Not decided yet</option></select><small>Standard ceiling and trim white do not count.</small></label><label class="pcec__field"><span>Colour Coverage</span><select name="colour_change"><option value="similar">Similar colour or tone</option><option value="light_to_dark">Light to darker colour or tone</option><option value="dark_to_light">Dark to lighter colour or tone</option><option value="unsure">Not sure</option></select><small>Large tone changes may need primer or additional coats.</small></label><label class="pcec__field"><span>Work Space</span><select name="occupancy"><option value="empty">Empty or mostly clear</option><option value="light">Some furniture to work around</option><option value="occupied">Fully furnished or in use</option></select><small>This helps account for protection and furniture handling.</small></label></div>
<div class="pcec__interior pcec__option-list pcec__paint-selection"><label><input type="checkbox" name="premium"><span><b>Premium paint or specialty coating</b><small>Select this if premium products or specialty finishes may be required.</small></span></label></div>
<?php if($additional_services||$conditions_to_review): ?><div class="pcec__interior pcec__specialty-sections"><p class="pcec__hint">These items will be reviewed during the site inspection and are not automatically included in the ballpark price.</p><div class="pcec__specialty-groups">
<?php if($additional_services): ?><section class="pcec__specialty-group"><h4>Additional services</h4><div class="pcec__specialties"><?php foreach($additional_services as $key=>$label): ?><label><input type="checkbox" name="specialty" value="<?php echo esc_attr($key); ?>"><span><?php echo esc_html($label); ?></span></label><?php endforeach; ?></div></section><?php endif; ?>
<?php if($conditions_to_review): ?><section class="pcec__specialty-group"><h4>Conditions to review</h4><div class="pcec__specialties"><?php foreach($conditions_to_review as $key=>$label): ?><label><input type="checkbox" name="specialty" value="<?php echo esc_attr($key); ?>"><span><?php echo esc_html($label); ?></span></label><?php endforeach; ?></div></section><?php endif; ?>
</div></div><?php endif; ?>
<div class="pcec__exterior pcec__grid pcec__grid--2"><label class="pcec__field"><span>Exterior Colours</span><select name="exterior_colours"><option value="one">One main colour</option><option value="two_three">Two or three colours</option><option value="four_plus">Four or more colours</option><option value="undecided">Not decided yet</option></select><small>Include contrasting siding, trim and feature colours.</small></label><label class="pcec__field"><span>Colour Coverage</span><select name="exterior_colour_change"><option value="similar">Similar colour or tone</option><option value="light_to_dark">Light to darker colour or tone</option><option value="dark_to_light">Dark to lighter colour or tone</option><option value="unsure">Not sure</option></select><small>Large tone changes may need primer or additional coats.</small></label></div>
<div class="pcec__exterior pcec__option-list pcec__paint-selection"><label><input type="checkbox" name="premium_exterior"><span><b>Premium exterior coating</b><small>Select this if premium exterior products or specialty coatings may be required.</small></span></label></div>
<?php if($exterior_services||$exterior_conditions): ?><div class="pcec__exterior pcec__specialty-sections"><p class="pcec__hint">These items will be reviewed during the site inspection and are not automatically included in the ballpark price.</p><div class="pcec__specialty-groups">
<?php if($exterior_services): ?><section class="pcec__specialty-group"><h4>Additional exterior services</h4><div class="pcec__specialties"><?php foreach($exterior_services as $key=>$label): ?><label><input type="checkbox" name="specialty" value="<?php echo esc_attr($key); ?>"><span><?php echo esc_html($label); ?></span></label><?php endforeach; ?></div></section><?php endif; ?>
<?php if($exterior_conditions): ?><section class="pcec__specialty-group"><h4>Conditions to review</h4><div class="pcec__specialties"><?php foreach($exterior_conditions as $key=>$label): ?><label><input type="checkbox" name="specialty" value="<?php echo esc_attr($key); ?>"><span><?php echo esc_html($label); ?></span></label><?php endforeach; ?></div></section><?php endif; ?>
</div></div><?php endif; ?>
<div class="pcec__actions"><button type="button" class="pcec__back">Back</button><button type="button" class="pcec__estimate">See my estimate</button></div></section>

<section class="pcec__step" data-step="6"><div class="pcec__result" aria-live="polite"><span>Ballpark project range</span><strong data-range></strong><small>Estimated midpoint: <b data-midpoint></b></small></div><p class="pcec__notice" data-tax-note></p><div class="pcec__line-items"><h3>Estimate details</h3><table><tbody data-lines></tbody></table></div><p>This is a planning range, not a quote. Final pricing depends on verified measurements, preparation, product selection, access and the confirmed scope.</p><p class="pcec__specialty-note" data-specialty-note hidden>Specialty work was identified and is not included in this range. It should be assessed during the on-site inspection.</p>
<?php if(!$admin_test): ?><div class="pcec__lead"><h3><?php echo esc_html($s['form_heading']); ?></h3><p><?php echo esc_html($s['cta_text']); ?></p><div class="pcec__grid pcec__grid--2"><label class="pcec__field"><span>Name *</span><input name="name" required></label><label class="pcec__field"><span>Email *</span><input type="email" name="email" required></label><label class="pcec__field"><span>Phone *</span><input name="phone" required></label><label class="pcec__field"><span>Street address *</span><input name="address" required></label><label class="pcec__field"><span>City *</span><input name="city" required></label><label class="pcec__field"><span>Postal / ZIP code *</span><input name="postal" required></label></div><label class="pcec__hp" aria-hidden="true">Website<input name="website" tabindex="-1"></label><p class="pcec__submit-message" role="alert"></p><button type="submit" class="pcec__email"><?php echo esc_html($s['submit_button_text']); ?></button></div><?php endif; ?><div class="pcec__actions"><button type="button" class="pcec__edit">Edit answers</button><button type="button" class="pcec__print">Print estimate</button></div></section>
</form>
<template data-room-template><div class="pcec__room"><label><span>Room name</span><input data-room-field="name" placeholder="eg. Living room"></label><label><span>Length</span><input type="number" inputmode="decimal" min="1" max="200" step="0.1" data-room-field="length" placeholder="12"></label><label><span>Width</span><input type="number" inputmode="decimal" min="1" max="200" step="0.1" data-room-field="width" placeholder="10"></label><label><span>Height</span><select data-room-field="height"><option value="h8">8 ft</option><option value="h9">9 ft</option><option value="h10">10 ft</option><option value="h11_12">11–12 ft</option><option value="vaulted">Vaulted</option></select></label><label><span>Type</span><select data-room-field="type"><option value="standard">Standard room</option><option value="kitchen">Kitchen</option><option value="bathroom">Bathroom</option><option value="hallway">Hallway</option><option value="other">Other</option></select></label><label class="pcec__room-accent"><span>Accent wall</span><input type="checkbox" data-room-field="accent" aria-label="Include one accent wall in this room"></label><button type="button" class="pcec__remove-room" aria-label="Remove room">Remove</button></div></template>
</div>

