// Generated by CoffeeScript 1.6.2
var cheerio;

cheerio = require('cheerio');

module.exports = function(content, opts) {
  var $, child, item, key, listItems, list_iterator, options, render_item_checkbox, _i, _len;

  $ = cheerio.load(content);
  opts || (opts = {});
  options = {
    disabled: false
  };
  for (key in opts) {
    options[key] = opts[key];
  }
  render_item_checkbox = function(html, checked, disabled) {
    var label;

    label = html.slice(3, +(html.length - 1) + 1 || 9e9);
    return "<label>\n  <input type=\"checkbox\"\n  class=\"task-list-item-checkbox\"\n  " + checked + "\n  " + disabled + "/>\n  " + label + "\n</label>";
  };
  list_iterator = function(item) {
    var detached, disabled, srcHtml;

    srcHtml = $(item).clone().children().remove('il, ul').end().html();
    disabled = options.disabled ? "disabled" : "";
    detached = $(item).children('il, ul');
    if (/^\[x\]/.test(srcHtml)) {
      return $(item).html(render_item_checkbox(srcHtml, "checked", disabled)).append(detached);
    } else if (/^\[ \]/.test(srcHtml)) {
      return $(item).html(render_item_checkbox(srcHtml, "", disabled)).append(detached);
    }
  };
  listItems = $('li');
  for (_i = 0, _len = listItems.length; _i < _len; _i += 1) {
    item = listItems[_i];
    child = $(item).children().first()['0'];
    list_iterator(item);
    if (child) {
      if (child.name === "p") {
        list_iterator(child);
      }
    }
  }
  return $.html();
};
