import insertElement from '../../common/insertElement';
import on from '../../common/on';
import {sendEvent} from '../../support/fshGa';
import {createDiv, createInput, createLabel} from '../../common/cElement';

function bioToggle() {
  sendEvent('bio', 'toggle');
}

function doCompression(bioCell) {
  var fshCompressor = createDiv({className: 'fshCompressor'});
  var toggle = insertElement(fshCompressor,
    createInput({id: 'fshCompressToggle', type: 'checkbox'}));
  on(toggle, 'change', bioToggle);
  insertElement(fshCompressor,
    createLabel({className: 'sendLink', htmlFor: 'fshCompressToggle'}));
  var fshCompress = insertElement(fshCompressor,
    createDiv({className: 'fshCompress'}));
  fshCompress.innerHTML = bioCell.innerHTML;
  bioCell.innerHTML = '';
  insertElement(bioCell, fshCompressor);
}

function getFontSize(bioCell) {
  var computedStyle = getComputedStyle(bioCell);
  return parseInt(computedStyle.getPropertyValue('font-size'), 10);
}

export default function compressBio(bioCell) {
  if (bioCell.clientHeight / getFontSize(bioCell) > 10) {
    doCompression(bioCell);
  }
}

@@ -83,16 +83,60 @@
 on/on';%0A
+import partial from '../../common/partial';%0A
 import %7B
@@ -263,151 +263,37 @@
 ion 
-bioToggle() %7B%0A  sendEvent('bio', 'toggle');%0A%7D%0A%0Afunction doCompression(bioCell) %7B%0A  var fshCompressor = createDiv(%7BclassName: 'fshCompressor'%7D);
+injectToggle(fshCompressor) %7B
 %0A  v
@@ -423,21 +423,113 @@
 e', 
-bioT
+partial(sendEvent, 'bio', 't
 oggle
+')
 );%0A
- 
+%7D%0A%0Afunction hideBlock(bioCell, fshCompressor) %7B%0A  var fshCompress =
  ins
@@ -564,21 +564,19 @@
   create
-Label
+Div
 (%7BclassN
@@ -583,29 +583,8 @@
 ame:
- 'sendLink', htmlFor:
  'fs
@@ -596,22 +596,16 @@
 ress
-Toggle
 '%7D));%0A  
 var 
@@ -600,20 +600,16 @@
 '%7D));%0A  
-var 
 fshCompr
@@ -611,33 +611,117 @@
 Compress
- = insertElement(
+.innerHTML = bioCell.innerHTML;%0A  bioCell.innerHTML = '';%0A%7D%0A%0Afunction doCompression(bioCell) %7B%0A  var 
 fshCompr
@@ -717,37 +717,34 @@
 ar fshCompressor
-,%0A  
  
+=
  createDiv(%7Bclas
@@ -766,83 +766,185 @@
 ress
+or
 '%7D)
-)
 ;%0A  
-fshCompress.innerHTML = bioCell.innerHTML;%0A  bioCell.innerHTML = ''
+injectToggle(fshCompressor);%0A  insertElement(fshCompressor,%0A    createLabel(%7BclassName: 'sendLink', htmlFor: 'fshCompressToggle'%7D));%0A  hideBlock(bioCell, fshCompressor)
 ;%0A  

reduce ABC