add_action('wp_footer', function() {
  if (!is_page('contract-screen-printing-calculator')) return;
  ?>
  <script>
  (function() {

    const DTF_PER_PIECE = {
      '24-35':   3.80,
      '36-47':   3.20,
      '48-71':   2.60,
      '72-143':  2.10,
      '144-299': 1.80,
      '300-499': 1.55,
      '500-999': 1.35,
      '1000+':   1.20
    };

    function getDTFPerPiece(qty) {
      if (qty < 24)   return null;
      if (qty < 36)   return DTF_PER_PIECE['24-35'];
      if (qty < 48)   return DTF_PER_PIECE['36-47'];
      if (qty < 72)   return DTF_PER_PIECE['48-71'];
      if (qty < 144)  return DTF_PER_PIECE['72-143'];
      if (qty < 300)  return DTF_PER_PIECE['144-299'];
      if (qty < 500)  return DTF_PER_PIECE['300-499'];
      if (qty < 1000) return DTF_PER_PIECE['500-999'];
      return DTF_PER_PIECE['1000+'];
    }

    function getSPBand(qty) {
      const bands = stCalculatorConfig.pricing.basePricing;
      if (qty < 24)   return bands['1-23'];
      if (qty < 36)   return bands['24-35'];
      if (qty < 48)   return bands['36-47'];
      if (qty < 72)   return bands['48-71'];
      if (qty < 144)  return bands['72-143'];
      if (qty < 300)  return bands['144-299'];
      if (qty < 500)  return bands['300-499'];
      if (qty < 1000) return bands['500-999'];
      return bands['1000-2499'];
    }

    function getSPTotal(qty, colors, hasUnderbase, isRepeat) {
      const effectiveColors = hasUnderbase ? Math.min(colors + 1, 7) : colors;
      const band = getSPBand(qty);
      const perPiece = band[String(effectiveColors)];
      if (!perPiece) return null;
      const screenFee = stCalculatorConfig.pricing.fees.screenSetup.value;
      const repeatFee = stCalculatorConfig.pricing.fees.repeatScreenSetup.valueTrue;
      const setupTotal = isRepeat
        ? effectiveColors * repeatFee
        : effectiveColors * screenFee;
      return setupTotal + (qty * perPiece);
    }

    function getRecommendation(qty, colors, hasUnderbase, isRepeat) {
      const dtfPPP   = getDTFPerPiece(qty);
      const dtfTotal = dtfPPP ? qty * dtfPPP : null;
      const spTotal  = getSPTotal(qty, colors, hasUnderbase, isRepeat);
      if (!spTotal && !dtfTotal) return null;
      if (!spTotal)  return { method: 'dtf',    dtfTotal, spTotal: null, diff: null, pct: null };
      if (!dtfTotal) return { method: 'screen', dtfTotal: null, spTotal, diff: null, pct: null };
      const diff    = Math.abs(dtfTotal - spTotal);
      const pct     = diff / Math.min(dtfTotal, spTotal);
      const cheaper = dtfTotal < spTotal ? 'dtf' : 'screen';
      const method  = pct < 0.12 ? 'tossup' : cheaper;
      return { method, cheaper, dtfTotal, spTotal, diff, pct };
    }

    function renderBanner(rec) {
      const box = document.getElementById('stk-method-rec');
      if (!box || !rec) return;
      const fmt = function(v) { return '$' + v.toFixed(2); };
      const styles = {
        dtf:    'background:#E1F5EE;border:1px solid #5DCAA5;color:#085041;',
        screen: 'background:#E6F1FB;border:1px solid #85B7EB;color:#0C447C;',
        tossup: 'background:#FAEEDA;border:1px solid #EF9F27;color:#633806;'
      };
      const msgs = {
        dtf: rec.diff != null
          ? '<strong>DTF printing recommended</strong> \u2014 saves ' + fmt(rec.diff) + ' vs screen printing for this run. No screen setup fees, fast turnaround on short runs.'
          : '<strong>DTF printing recommended</strong> \u2014 quantity is below screen printing minimums (24 pcs).',
        screen: rec.diff != null
          ? '<strong>Screen printing recommended</strong> \u2014 saves ' + fmt(rec.diff) + ' (' + (rec.pct*100).toFixed(0) + '% less) vs DTF at this quantity. Best value and print quality for this run.'
          : '<strong>Screen printing recommended</strong> for this quantity and color count.',
        tossup: '<strong>Either method works here</strong> \u2014 costs are within 12% (' + fmt(rec.diff) + ' difference). <a href="tel:2032486248" style="color:inherit;font-weight:600;">Call us at 203-248-6248</a> and we\'ll recommend the best option based on your artwork and turnaround.'
      };
      box.style.cssText = 'display:block;padding:12px 16px;border-radius:8px;font-size:14px;line-height:1.6;margin:16px 0;' + styles[rec.method];
      box.innerHTML = msgs[rec.method];
    }

    function readValues() {
      const qtyEl        = document.getElementById('st-calc-numberOfPrints');
      const qty          = qtyEl ? parseInt(qtyEl.value) || 0 : 0;
      const colEl        = document.querySelector('.st-calculator__form-group--numberOfColors input[type="number"]');
      const colors       = colEl ? Math.min(parseInt(colEl.value) || 1, 7) : 1;
      const ubEl         = document.getElementById('st-calc-underbaseRequired');
      const hasUnderbase = ubEl ? ubEl.checked : false;
      const repEl        = document.getElementById('st-calc-repeatScreenSetup');
      const isRepeat     = repEl ? repEl.checked : false;
      return { qty, colors, hasUnderbase, isRepeat };
    }

    function update() {
      const vals = readValues();
      const box  = document.getElementById('stk-method-rec');
      if (vals.qty < 1) {
        if (box) box.style.display = 'none';
        return;
      }
      var rec = getRecommendation(vals.qty, vals.colors, vals.hasUnderbase, vals.isRepeat);
      renderBanner(rec);
    }

    function injectBanner() {
      if (document.getElementById('stk-method-rec')) return;
      var banner = document.createElement('div');
      banner.id = 'stk-method-rec';
      banner.setAttribute('aria-live', 'polite');
      banner.style.display = 'none';
      var target = document.querySelector('.st-calculator__card');
      if (target) {
        target.parentNode.insertBefore(banner, target);
      } else {
        var form = document.querySelector('.st-calculator');
        if (form) form.appendChild(banner);
      }
    }

    function init() {
      injectBanner();
      var container = document.querySelector('.st-calculator') || document.body;
      container.addEventListener('input',  update);
      container.addEventListener('change', update);
      container.addEventListener('click',  function() { setTimeout(update, 50); });
      new MutationObserver(update).observe(container, {
        childList: true, subtree: true, attributes: true,
        attributeFilter: ['aria-pressed', 'checked']
      });
      update();
    }

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', init);
    } else {
      setTimeout(init, 300);
    }

  })();
  </script>
  <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://screentekct.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://screentekct.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://screentekct.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://screentekct.com/wp-sitemap-posts-portfolio-1.xml</loc></sitemap><sitemap><loc>https://screentekct.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://screentekct.com/wp-sitemap-taxonomies-post_tag-1.xml</loc></sitemap><sitemap><loc>https://screentekct.com/wp-sitemap-taxonomies-project-type-1.xml</loc></sitemap></sitemapindex>
