/**
 * EnterpriseMouldAssessment — Final assembly.
 * Wires Sections A–F into a single controlled component.
 *
 * Props:
 *   value    (object) — Full assessment state (use DEFAULT_ASSESSMENT as initial value)
 *   onChange (func)   — Called with updated assessment on any change
 *   aiResult (object) — Latest scan (pre-fills AI species/severity badge)
 */

var EnterpriseMouldAssessment = function (props) {
    var value    = props.value || window._EMA_DEFAULT_ASSESSMENT;
    var onChange = props.onChange;
    var aiResult = props.aiResult || null;

    // Active section accordion — null means all visible (no accordion on mobile,
    // sections stack naturally for a long-form experience)
    // We keep all sections open but use visual dividers for clarity.

    return (
        <div className="space-y-6">

            {/* Enterprise badge */}
            <div className="flex items-center gap-2 px-1">
                <span className="material-symbols-outlined text-forest text-lg">verified</span>
                <div>
                    <p className="text-[10px] font-black text-forest uppercase tracking-widest">Enterprise Assessment</p>
                    <p className="text-[11px] text-forest font-medium">Dampness & Mould Assessment Tool (DMAT)</p>
                </div>
            </div>

            {/* AI pre-fill banner — shown when scan result available */}
            {aiResult && (
                <div className="bg-primary/30 rounded-xl p-3 flex items-start gap-2.5 border border-primary/20">
                    <span className="material-symbols-outlined text-forest text-base mt-0.5 shrink-0">auto_awesome</span>
                    <div className="flex-1 min-w-0">
                        <p className="text-[11px] font-extrabold text-forest">AI Analysis Pre-fill</p>
                        <p className="text-[11px] text-forest font-medium leading-relaxed">
                            {aiResult.verdict || 'Scan result'} detected
                            {FeatureFlags.isEnabled('SPECIES_LIST') && aiResult.speciesTop ? ' — ' + aiResult.speciesTop.label : ''}
                            {aiResult.percentage ? ' (' + aiResult.percentage + '% confidence)' : ''}.
                            Review and confirm below.
                        </p>
                    </div>
                </div>
            )}

            {/* Divider helper */}
            <div className="h-px bg-forest/10"></div>

            {/* Section A — General Info */}
            <window._EMA_SectionGeneralInfo value={value} onChange={onChange} />

            <div className="h-px bg-forest/10"></div>

            {/* Section B — Odour */}
            <window._EMA_SectionOdour value={value} onChange={onChange} />

            <div className="h-px bg-forest/10"></div>

            {/* Section C — Component Matrix */}
            <window._EMA_SectionComponents value={value} onChange={onChange} />

            <div className="h-px bg-forest/10"></div>

            {/* Section D — Environmental Readings */}
            <window._EMA_SectionEnvironmental value={value} onChange={onChange} />

            <div className="h-px bg-forest/10"></div>

            {/* Section E — Remediation Planning */}
            <window._EMA_SectionRemediation value={value} onChange={onChange} />

            <div className="h-px bg-forest/10"></div>

            {/* Section F — Sign-off + General Notes */}
            <window._EMA_SectionSignOff value={value} onChange={onChange} />

        </div>
    );
};

// Override the placeholder set in EnterpriseMouldAssessment.jsx
window.EnterpriseMouldAssessment = EnterpriseMouldAssessment;
