(function (api) {
  'use strict';

  if (!api) {
    return;
  }

  function setText(selector, value, fallback) {
    var el = document.querySelector(selector);
    if (!el) {
      return;
    }
    var next = (value || '').toString().trim();
    if (!next) {
      next = el.getAttribute('data-default') || fallback || '';
    }
    el.textContent = next;
  }

  api('blogname', function (setting) {
    setting.bind(function (value) {
      setText('.brand__name', value, 'TTSun Solar');
    });
  });

  api('blogdescription', function (setting) {
    setting.bind(function (value) {
      setText('.brand__tagline', value, 'Clean Energy Solutions');
    });
  });
})(wp.customize);
