#line 3669 "/home/travis/build/felix-lang/felix/src/packages/flx_web.fdoc"
  include "./fileseq-interface";
  
  include "./button-interface";
  var button-factory : unit -> button-factory_t;
  
  fun setup(config_data:string) = {
    eprintln$ "Setup fdoc_fileseq " + config_data;
    button-factory = Dynlink::load-plugin-func0 [button-factory_t] (dll-name="fdoc_button");
    return 0;
  }
  
  object fdoc_fileseq (filename: string) implements fileseq-control_t =
  {
    var button = #button-factory;
    method fun whatami()=> "Filename sequence navigation object";
    method fun get-jscript() => "<script> function nop(dummy) {} </script>";
  
    fun calnav() =
    {
      val relfile = match (filename,'/').split.rev with | Cons(h,_) => h | #Empty => "";
      var lpos = relfile.len.int;
      while lpos > 0 and not isdigit(relfile.[lpos - 1]) do
         --lpos;
      done
      assert lpos == 0 or relfile.[lpos - 1].isdigit;
      var fpos = lpos;
      while fpos > 0 and isdigit(relfile.[fpos - 1]) do --fpos; done
      assert fpos == 0 or relfile.[fpos].isdigit;
      val digits =
        if fpos >=0 and lpos > fpos then
          relfile.[fpos to lpos]
        else ""
      ;
  
      val n = digits.len.int;
      val v = digits.int;
      val vnext = v + 1;
      val vprev = v - 1;
      var snext = (f"%010d" vnext).[10-n to];
      var sprev= (f"%010d" vprev).[10-n to];
  
      snext = relfile.[to fpos] + snext + relfile.[lpos to];
      sprev = relfile.[to fpos] + sprev + relfile.[lpos to];
      docindex := relfile.[to fpos] + "index" + relfile.[lpos to];
  
      return
        if digits == "" then
          None[int],None[string],None[string],docindex
        elif vprev > 0 then
          Some v,Some sprev, Some snext,docindex
        else
          Some v,None[string], Some snext,docindex
      ;
    }
  
    method fun shownav() =>
      match calnav() with
      | _,Some sprev, Some snext, docindex =>
          "<a href='"+sprev+"'>"+button.make-button(id="prev", text="Prev", onclick="nop")+"</a> " +
          "<a href='"+snext+"'>"+button.make-button(id="next", text="Next", onclick="nop")+"</a> " +
          "<a href='"+docindex+"'>"+button.make-button(id="index", text="Index", onclick="nop")+"</a> "
      | _,#None, Some snext, docindex =>
         "<a href='"+snext+"'>"+button.make-button(id="next", text="Next", onclick="nop")+"</a> "+
         "<a href='"+docindex+"'>"+button.make-button(id="index", text="Index", onclick="nop")+"</a>"
      | _,#None, #None,_ => ""
      endmatch
    ;
  
    method fun docnum()=>
      match calnav() with
      | #None,_,_,_ => ""
      | Some v,_,_,_ => str v + "."
    ;
  
  }
  
  export fun setup of (string) as "fdoc_fileseq_setup";
  export fun fdoc_fileseq of (string) as "fdoc_fileseq";