local t = {}

-------------------------------------------------------------
-- KES: 1=ez/min, 2=tu/te, 3=ew/wê-wî, 4=em/me, 5=hûn/we, 6=ew/wan
-- DEM: 
---- IndPresent + kes
---- IndPreterite + kes
---- IndImperfect + kes
---- IndPluperfect + kes
---- IndPerfect + kes
---- IndPQPNCons + kes
---- IndFuture + kes
---- IndFuturePerfect + kes
---- SubPresent + kes
---- SubPreterite + kes
---- SubImperfect + kes
---- SubPluperfect + kes
---- CondPresent + kes
---- CondPreterite + kes
---- ImpPresent2
---- ImpPresent5
-- MÎNAK:
--- IndPresent5: Raweya pêşkerî (Ind), dem = niha (Present), kes = em (5)
--- SubImperfect2: Raweya xwestekî (Sub), dem = Raboriya bilaniyê (Imperfect), kes = tu (2)

-- Kurdî:
--- Ind: Raweya pêşkerî
--- Sub: Raweya xwestekî (bilanî, daxwazî)
--- Cond: Raweya mercî (hekînî)
--- Imp: Raweya fermanî
--- Inf: Rader
--- Part: Çêbiwar 
----- Present: Dema niha
----- Preterite: Raboriya sade
----- Imperfect: Çîrokiya dema niha
----- Pluperfect: Çirokiye boriya têdeyî
----- Perfect: Dema boriya dûdar
----- PQPNCons: Çîrokiya boriya dûdar
----- Future: Dema bê
----- Future perfect: Dahatiya pêş
-------------------------------------------------------------
-- Rengê kesk (color:green) bo cînavên gerguhêzan (têperan).
function kesk(kes)
	return '<span style="color:green">' .. kes .. ' ' .. '</span>'
end

function t.kes(dem, form)
   local kes1 = {'ez','tu','ew','em','hûn','ew'}
   local kes2 = {'ez ê','tu yê','ew ê','em ê','hûn ê','ew ê'}
   local kes3 = {kesk('min'),kesk('te'),kesk('wê/wî'),kesk('me'),kesk('we'),kesk('wan')}
   local kes4 = {kesk('min')..'ê',kesk('te')..'yê',kesk('wê/wî')..'yê',kesk('me')..'yê',kesk('we')..'yê',kesk('wan')..'ê'}
 
   local l = mw.ustring.sub(dem, -1)
   local n = tonumber(l)
 
   if (form == 'gerguhêz') then
      if (dem == 'IndPresent'.. l) then return kes1[n] end
      if (dem == 'IndFuture'.. l) then return kes2[n] end
      if (dem == 'SubPresent' .. l) then return '(bila) ' .. kes1[n] end
      if (dem == 'IndPreterite' .. l or dem == 'IndImperfect' .. l or dem == 'IndPluperfect' .. l
    	  or dem == 'IndPerfect' .. l or dem == 'IndPQPNCons'.. l) then  return kes3[n]  end
      if (dem == 'SubPreterite' .. l or dem == 'SubImperfect' .. l or dem == 'SubPluperfect' .. l) then return '(bila) ' .. kes3[n] end
      if (dem == 'IndFuturePerfect' .. l or dem == 'CondPresent' .. l or dem == 'CondPreterite' .. l) then return kes4[n] end
   elseif (form == 'negerguhêz') then
      if (dem == 'IndPresent' .. l or dem == 'IndPreterite' .. l or dem == 'IndImperfect' .. l
    	  or dem == 'IndPluperfect' .. l or dem == 'IndPerfect' .. l or dem == 'IndPQPNCons' .. l) then return kes1[n] end
      if (dem == 'IndFuture'..l or dem == 'IndFuturePerfect' .. l
      	  or dem == 'CondPresent' .. l or dem == 'CondPreterite' .. l) then return kes2[n] end
      if (dem == 'SubPreterite' .. l or dem == 'SubImperfect' .. l or dem == 'SubPluperfect' .. l) then return '(bila) ' .. kes1[n] end
      if (dem == 'SubPresent' .. l) then return '(bila) ' .. kes1[n] end
   end
   if (dem == 'ImpPresent2') then return '(tu)' end
   if (dem == 'ImpPresent5') then return '(hûn)' end
end
-------------------------------------------------------------------------------------------------------------
-- AGAHÎ:
-- pêşgira "di": "IndPresent"(niha), "IndImperfect"(bori)
-- pêşgira "bi": "IndFuture"(niha), "SubPresent"(niha), "SubImperfect"(bori) = "CondPresent"(bori)

--radîkal "niha": "IndPresent"(di)(na), "IndFuture"(bi)(ne) = "SubPresent"(bi)(ne)

--radîkal "borî": "IndPreterite"(-)(ne), "IndImperfect"(di)(ne), "IndPluperfect"(-)(ne),
--------------- "IndPerfect"(-)(ne), "IndPQPNCons"(-)(ne), "IndFuturePerfect"(-)(ne),
--------------- "SubPreterite"(-)(ne), "SubImperfect"(bi)(ne) = "CondPresent"(bi)(ne),
---------------"SubPluperfect"(-)(ne) = "CondPreterite"(-)(ne)
-------------------------------------------------------------------------------------------------------------
--                      Fonksyonên pêwîst
-------------------------------------------------------------
d = require('Modul:ku-tewandin/dijrêzik')
-------------
-- Di / Bi --
-------------
-- Pêşgira "di" bo demên "IndPresent"(niha) û "IndImperfect"(bori)
-- Bo neyînî: pêşgira "di" tenê di nav dema "IndImperfect" de tê bikaranîn.
function di(radikal, neyini, p_di)
   if (neyini == 'ne') then return '' end 
   
   if d.dijrezikDi[radikal] then return d.dijrezikDi[radikal]
   elseif p_di then return p_di
   elseif mw.ustring.find(radikal, '^[ai]') then return 'd'
   elseif mw.ustring.find(radikal, '^[êî]') then return 't' -- "e" = t? (mînak: herrîn -er-: ez terim, tu terî, ...)
   else return 'di'
   end
end

-- Pêşgira "bi" bo demên "IndFuture"(niha), "SubPresent"(niha), "SubImperfect"(bori) = "CondPresent"
function bi(radikal, neyini, pesgir, valahi, p_bi)
   if (neyini == 'ne') then return '' end  -- Di nav tewînên neyînî de "bi" na tê bikranîn.
   if (pesgir ~= nil and pesgir ~= '' and valahi ~= ' ') then return '' end -- Bo "lêkerên pêkhatî" (rakirin, çêkirin, ...): "bi" na tê bikaranîn.
      
   if d.dijrezikBi[radikal] then return d.dijrezikBi[radikal]
   elseif p_bi then return p_bi
   elseif mw.ustring.find(radikal, '^[aeêiîouû]') then return 'b'
   else return 'bi'
   end
end

------------
-- Neyînî --
------------
function b(bold) return '<b>' .. bold .. '</b>' end -- nivîsa stûr ji bo pêşgira neyînî
	
--- Neyînî (na) bo dema "IndPresent"
function na(radikal, neyini, p_na)
   if (neyini == nil or neyini == '') then return ''
   elseif (neyini == 'ne') then
   	  if p_na then return b(p_na) end
   	  if d.dijrezikNa[radikal] then return b(d.dijrezikNa[radikal])
      elseif mw.ustring.find(radikal, '^[eêiîouû]') then return b('nay')
      elseif mw.ustring.find(radikal, '^%wa') then return b('ni') -- tîpa duyem "a" ye (karîn, zanîn, ...)
      elseif mw.ustring.find(radikal, '^a') then return b('n')    -- tîpa yekem "a" ye
      else return b('na')
      end
   end
end

--- Neyînî (ne) bo hemû demên din
function ne(radikal, neyini, p_ne)
   if (neyini == nil or neyini == '') then return ''
   elseif (neyini == 'ne') then
   	  if p_ne then return b(p_ne) end
   	  if d.dijrezikNe[radikal] then return b(d.dijrezikNe[radikal])
      elseif mw.ustring.find(radikal, '^[eêiîouû]') then return b('ney')
      elseif mw.ustring.find(radikal, '^a') then return b('n')
      else return b('ne')
      end
   end
end

----------------
--- îy --> iy---
----------------
function r_bori(bori, pasgir)
   if mw.ustring.find(bori, 'î$') and mw.ustring.find(pasgir, '^y') then
   	  return mw.ustring.gsub(bori,'î$','i') 
   	else return bori 
    end
end
function r_niha(niha, pasgir)
   if mw.ustring.find(niha, 'î$') and mw.ustring.find(pasgir, '^y') then
   	  return mw.ustring.gsub(niha,'î$','i')
   else return niha 
   end
end
-------------------------------------------------------------
--                      TEWANDIN
-------------------------------------------------------------
function t.tewandin(leker, dem, neyini, form, pasgir, pesgir, valahi, niha, bori, p_bi, p_di, p_na, p_ne)
   if (pasgir == nil) then
   		pasgir = ''
   else
   		pasgir = ' ' .. pasgir
   end
   if (pesgir == nil) then pesgir = '' end
   if (valahi == 'erê' or valahi == '1') then valahi = ' ' else valahi = '' end
   
   local IndPresent = {}
   local IndPreterite = {}
   local IndImperfect = {}
   local IndPluperfect = {}
   local IndPerfect = {}
   local IndPQPNCons = {}
   local IndFuture = {}
   local IndFuturePerfect = {}
   local SubPresent = {}
   local SubPreterite = {}
   local SubImperfect = {}
   local SubPluperfect = {}
   local CondPresent = {}
   local CondPreterite = {}
   
   local ImpPresent2
   local ImpPresent5
   
   ------------------------------
   -- Paşgir bo lêkerên "niha" --
   ------------------------------
   if mw.ustring.find(niha, '[aeêiîouû]$') then
    nihaPasgir = {'m', 'yî', '', 'n', 'n', 'n'}
   else
    nihaPasgir = {'im', 'î', 'e', 'in', 'in', 'in'}
   end
   --------------------------------------
   -- Paşgir bo lêkerên borî "negerguhêz" (têneper) --
   --------------------------------------
   -- "IndPreterite" + "IndImperfect"
   local dm = mw.ustring.gsub(dem, '[123456]','')
      
   if mw.ustring.find(bori, '[aeêiouû]$') then
      boriPasgir = {'m', 'yî', '', 'n', 'n', 'n'}
   elseif mw.ustring.find(bori, 'î$') then
      boriPasgir = {'m', '', '', 'n', 'n', 'n'}
      if (dm == 'IndImperfect') then
        boriPasgir = {'yam', 'yayî', 'ya', 'yan', 'yan', 'yan'}
      end
   else
      boriPasgir = {'im', 'î', '', 'in', 'in', 'in'}
   end
   -- Yên din...
   if mw.ustring.find(bori, '[(ya)îû]$') then
     pasgirPluperfect = {'bûm', 'bûyî', 'bû', 'bûn', 'bûn', 'bûn'}
     pasgirPerfect = {'me', 'yî', 'ye', 'ne', 'ne', 'ne'}
     pasgirPQPNCons = {'bûme', 'bûyiye', 'bûye', 'bûne', 'bûne', 'bûne'}
     pasgirFuturePerfect = {'bim', 'bî', 'be', 'bin', 'bin', 'bin'}
     if mw.ustring.find(bori, 'î$') then
     	pasgirSubImperfect = {'yama', 'yayî', 'yaya', 'yana', 'yana', 'yana'}
     elseif mw.ustring.find(bori, '[û(ya)]$') then
     	pasgirSubImperfect = {'ma', 'yayî', 'ya', 'na', 'na', 'na'}
     end
     pasgirSubPluperfect = {'bûma', 'bûyayî', 'bûya', 'bûna', 'bûna', 'bûna'}
     if mw.ustring.find(bori, '(ya)$') then pasgirSubImperfect[2] = 'yî' end
   elseif mw.ustring.find(bori, '[aeêiou]$') then
     pasgirPluperfect = {'yibûm', 'yibûyî', 'yibû', 'yibûn', 'yibûn', 'yibûn'}
     pasgirPerfect = {'me', 'yî', 'ye', 'ne', 'ne', 'ne'}
     pasgirPQPNCons = {'yibûme', 'yibûyiye', 'yibûye', 'yibûne', 'yibûne', 'yibûne'}
     pasgirFuturePerfect = {'yibim', 'yibî', 'yibe', 'yibin', 'yibin', 'yibin'}
     pasgirSubImperfect = {'ma', 'yayî', 'ya', 'na', 'na', 'na'}                          -- "SubImperfect" = "CondPresent"
     pasgirSubPluperfect = {'yibûma', 'yibûyayî', 'yibûya', 'yibûna', 'yibûna', 'yibûna'} -- "SubPluperfect" = "CondPreterite"
   else
     pasgirPluperfect = {'ibûm', 'ibûyî', 'ibû', 'ibûn', 'ibûn', 'ibûn'}
     pasgirPerfect = {'ime', 'iyî', 'iye', 'ine', 'ine', 'ine'}
     pasgirPQPNCons = {'ibûme', 'ibûyiye', 'ibûye', 'ibûne', 'ibûne', 'ibûne'}
     pasgirFuturePerfect = {'ibim', 'ibî', 'ibe', 'ibin', 'ibin', 'ibin'}
     pasgirSubImperfect = {'ama', 'ayî', 'a', 'ana', 'ana', 'ana'}
     pasgirSubPluperfect = {'ibûma', 'ibûyayî', 'ibûya', 'ibûna', 'ibûna', 'ibûna'}
   end
   ------------------------------------
   -- Paşgir bo lêkerên borî "gerguhêz" (têper) --
   ------------------------------------
   if mw.ustring.find(bori, '[eêiou]$') then
     pasgirPluperfect3 = 'yibû'
     pasgirPerfect3 = 'ye'
     pasgirPQPNCons3 = 'yibûye'
     pasgirFuturePerfect3 = 'yibe'
     pasgirSubImperfect3 = 'ya'
     pasgirSubPluperfect3 = 'yibûya'
   elseif mw.ustring.find(bori, '[aîû]$') then
     pasgirPluperfect3 = 'bû'
     pasgirPerfect3 = 'ye'
     pasgirPQPNCons3 = 'bûye'
     pasgirFuturePerfect3 = 'be'
     pasgirSubImperfect3 = 'ya'
     pasgirSubPluperfect3 = 'bûya'     
   elseif mw.ustring.find(bori, 'î$') then
     pasgirPluperfect3 = 'bû'
     pasgirPerfect3 = 'ye'
     pasgirPQPNCons3 = 'bûye'
     pasgirFuturePerfect3 = 'be'
     pasgirSubImperfect3 = 'ya'
     pasgirSubPluperfect3 = 'bûya'
   else
     pasgirPluperfect3 = 'ibû'
     pasgirPerfect3 = 'iye'
     pasgirPQPNCons3 = 'ibûye'
     pasgirFuturePerfect3 = 'ibe'
     pasgirSubImperfect3 = 'a'
     pasgirSubPluperfect3 = 'ibûya'
   end
-------------------------------------------------------------
--                      RADÎKAL NIHA
-------------------------------------------------------------
   for i = 1, 6 do
     IndPresent[i] = pesgir .. valahi .. di(niha, neyini, p_di) .. na(niha, neyini, p_na) .. r_niha(niha, nihaPasgir[i]) .. nihaPasgir[i]
   	 IndFuture[i] = pesgir .. valahi .. bi(niha, neyini, pesgir, valahi, p_bi) .. ne(niha, neyini, p_ne) .. r_niha(niha, nihaPasgir[i]) .. nihaPasgir[i]
   	 SubPresent[i] = IndFuture[i]
   end
  -------------
  -- FERMANÎ --
  -------------
     if (d.dijrezikImp[niha] and pesgir == nil) then
         if (neyini == '') then
     	    ImpPresent2 = d.dijrezikImp[niha][1]
     	    ImpPresent5 = d.dijrezikImp[niha][2]
     	 end
     	 if (neyini == 'ne') then
     	    ImpPresent2 = d.dijrezikImp[niha][3]
     	    ImpPresent5 = d.dijrezikImp[niha][4]
     	 end
     else
       ImpPresent2 = IndFuture[3]
       ImpPresent5 = IndFuture[5]
     end
-------------------------------------------------------------
--                      RADÎKAL BORÎ
-------------------------------------------------------------
   if (form == 'gerguhêz') then
     for i = 1, 6 do
   	    IndPreterite[i] = pesgir .. valahi.. ne(bori, neyini, p_ne) .. bori
   	    IndImperfect[i] = pesgir .. valahi .. ne(di(bori,'', p_di), neyini) .. di(bori,'', p_di) .. bori
   	    IndPluperfect[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirPluperfect3) .. pasgirPluperfect3
   	    IndPerfect[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirPerfect3) .. pasgirPerfect3
   	    IndPQPNCons[i] = pesgir .. valahi.. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirPQPNCons3) .. pasgirPQPNCons3
   	    IndFuturePerfect[i] = pesgir .. valahi.. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirFuturePerfect3) .. pasgirFuturePerfect3
   	     
   	    SubPreterite[i] = IndFuturePerfect[i]
   	    SubImperfect[i] = pesgir .. valahi .. bi(bori, neyini, pesgir, valahi, p_bi) .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirSubImperfect3) .. pasgirSubImperfect3
   	    SubPluperfect[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirSubPluperfect3) .. pasgirSubPluperfect3
   	     
   	    CondPresent[i] = SubImperfect[i]
   	    CondPreterite[i] = SubPluperfect[i]
     end
   elseif (form == 'negerguhêz') then
     for i = 1, 6 do
        IndPreterite[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, boriPasgir[i]) .. boriPasgir[i]
        IndImperfect[i] = pesgir .. valahi .. ne(di(bori, '', p_di), neyini) .. di(bori, '', p_di) .. r_bori(bori, boriPasgir[i]) .. boriPasgir[i]
   	    IndPluperfect[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirPluperfect[i]) .. pasgirPluperfect[i]
   	    IndPerfect[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirPerfect[i]) .. pasgirPerfect[i]
   	    IndPQPNCons[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirPQPNCons[i]) ..  pasgirPQPNCons[i]
   	    IndFuturePerfect[i] = pesgir .. valahi .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirFuturePerfect[i]) .. pasgirFuturePerfect[i]
   	     
   	    SubPreterite[i] = IndFuturePerfect[i]
   	    SubImperfect[i] = pesgir .. valahi.. bi(bori, neyini, pesgir, valahi, p_bi) .. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirSubImperfect[i]) .. pasgirSubImperfect[i]
   	    SubPluperfect[i] = pesgir .. valahi.. ne(bori, neyini, p_ne) .. r_bori(bori, pasgirSubPluperfect[i]) .. pasgirSubPluperfect[i]
   	     
   	    CondPresent[i] = SubImperfect[i]
   	    CondPreterite[i] = SubPluperfect[i]
     end
   elseif (form ~= nil) then return '<span style="color:red">form="gerguhêz" an "negerguhêz"</span>'
   end

   -- Parametre
   for i = 1, 6 do
  	 local s = tostring(i)
     if (dem == 'IndPresent' .. s) then tew = IndPresent[i] .. pasgir end
     if (dem == 'IndPreterite' .. s) then tew = IndPreterite[i] .. pasgir end
     if (dem == 'IndImperfect' .. s) then tew = IndImperfect[i] .. pasgir end
     if (dem == 'IndPluperfect' .. s) then tew = IndPluperfect[i] .. pasgir end
     if (dem == 'IndPerfect' .. s) then tew = IndPerfect[i] .. pasgir end
     if (dem == 'IndPQPNCons' .. s) then tew = IndPQPNCons[i] end
     if (dem == 'IndFuture' .. s) then tew = IndFuture[i] .. pasgir end
     if (dem == 'IndFuturePerfect' .. s) then tew = IndFuturePerfect[i] .. pasgir end
     if (dem == 'SubPresent' .. s) then tew = SubPresent[i] .. pasgir end
     if (dem == 'SubPreterite' .. s) then tew = SubPreterite[i] .. pasgir end
     if (dem == 'SubImperfect' .. s) then tew = SubImperfect[i] .. pasgir end
     if (dem == 'SubPluperfect' .. s) then tew = SubPluperfect[i] .. pasgir end
     if (dem == 'CondPresent' .. s) then tew = CondPresent[i] .. pasgir end
     if (dem == 'CondPreterite' .. s) then tew = CondPreterite[i] .. pasgir end
   end
     if (dem == 'ImpPresent2') then tew = ImpPresent2 .. pasgir end  
     if (dem == 'ImpPresent5') then tew = ImpPresent5 .. pasgir end
     
   return tew
end

-------------------------------------------------------------------------------------------------------------------------------
--                                            DAWÎ
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------
-- Tewandin dirêj: niha2 + niha3 + bori2
-------------------------------------------------------------
function t.tewandinDirej(leker, dem, neyini, form, pasgir, pesgir, valahi, niha, niha2, niha3, bori, bori2, p_bi, p_di, p_na, p_ne)
   local dm = mw.ustring.gsub(dem, '[123456]','')
   
   -- Radîkal "niha2" û "niha3"
   if (dm == 'IndPresent' or dm == 'IndFuture' or dm == 'SubPresent' or dm == 'ImpPresent') then
      if (niha2 == nil or niha2 == '') then tewNiha2 = '' else
        tewNiha2 = ' / ' .. t.tewandin(leker, dem, neyini, form, pasgir, pesgir, valahi, niha2, bori, p_bi, p_di, p_na, p_ne)
      end
      if (niha3 == nil or niha3 == '') then tewNiha3 = '' else
        tewNiha3 = ' / ' .. t.tewandin(leker, dem, neyini, form, pasgir, pesgir, valahi, niha3, bori, p_bi, p_di, p_na, p_ne)
      end
   else
   	  if (niha == nil) then niha = '' end
      tewNiha2 = ''
      tewNiha3 = ''
   end
   
   -- Radîkal "bori2"
   if (dm == 'IndPreterite' or dm == 'IndImperfect' or dm == 'IndPluperfect' or dm == 'IndPerfect'
       or dm == 'IndPQPNCons' or dm == 'IndFuturePerfect' or dm == 'SubPreterite' or dm == 'SubImperfect'
       or dm == 'SubPluperfect' or dm == 'CondPresent' or dm == 'CondPreterite') then
      if (bori2 == nil or bori2 == '') then tewBori2 = '' else
        tewBori2 = ' / ' .. t.tewandin(leker, dem, neyini, form, pasgir, pesgir, valahi, niha, bori2, p_bi, p_di, p_na, p_ne)
      end
   else
   	  if (bori == nil) then bori = '' end
      tewBori2 = ''
   end  
   
   tew = t.tewandin(leker, dem, neyini, form, pasgir, pesgir, valahi, niha, bori, p_bi, p_di, p_na, p_ne)
   tewBori2 = mw.ustring.gsub(tewBori2, ' / ' .. tew, '')
   
   return tew .. tewNiha2 .. tewNiha3 .. tewBori2
end

---------------------------------------------------------------------------
-- Bo tabloyên {{tewîn}} û {{tewîn+}} hatiye çêkirin.
-- Bikaranîn: {{#invoke:ku-tewandin|tew|1=dem|2=neyini}}
---------------------------------------------------------------------------
function t.tew(frame)
   local args = frame:getParent().args
   local dem = frame.args[1]
   local neyini = frame.args[2]
   local leker = args[1]
   local niha = args['niha']
   local bori = args['borî']
   local form = args['form']
   local pasgir = args['paşgir']
   local pesgir = args['pêşgir']
   local valahi = args['valahî']
   
   local niha2 = args['niha2']
   local niha3 = args['niha3']
   local bori2 = args['borî2']
   
   local bi = args['bi']
   local di = args['di']
   local na = args['na']
   local ne = args['ne']
   
   return t.tewandinDirej(leker, dem, neyini, form, pasgir, pesgir, valahi, niha, niha2, niha3, bori, bori2, bi, di, na, ne)
end

function t.get_comma_separated_forms(frame)
   local args = frame:getParent().args
   local leker = frame.args[1]
   local niha = frame.args['niha']
   local bori = frame.args['borî']
   local form = frame.args['form']
   local pasgir = frame.args['paşgir']
   local pesgir = frame.args['pêşgir']
   local valahi = frame.args['valahî']
   
	demList = {'IndPresent','IndPreterite','IndImperfect','IndPluperfect','IndPerfect','IndPQPNCons','IndFuture','IndFuturePerfect',
		'SubPresent','SubPreterite','SubImperfect','SubPluperfect',
		'CondPresent','CondPreterite'}

   local tew_results = {}
   local forms = {}
   
   function removeTags(tag)
		tag = mw.ustring.gsub(tag, '%[%[(.+)%|(.+)%]%]', '%2')
		tag = mw.ustring.gsub(tag, '<b>(.+)</b>', '%1')
		tag = mw.ustring.gsub(tag, '<span(.*)>(.*)</span>', '%2')
		return tag
   end
   
	for _, v in ipairs(demList) do
		for i = 1, 6 do
			dem = v .. i
			tewandin = removeTags(t.tewandin(leker, dem, neyini, form, pasgir, pesgir, valahi, niha, bori))
			table.insert(forms, tewandin)
			tewandin = removeTags(t.tewandin(leker, dem, 'ne', form, pasgir, pesgir, valahi, niha, bori))
			table.insert(forms, tewandin)
		end
	end
	
	-- Remove duplicate elements
	local newForms = {}
	local checkForms = {}
	
	for _, v in ipairs(forms) do
		if not checkForms[v] then
			checkForms[v] = true
			table.insert(newForms, v)
		end
	end
   
   return table.concat(newForms, ',') 
end

return t