require('strict')

--[=[
Implements [[Template:PD-US-no-renewal]]
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local PD = require('Module:PD')

function p._PD_US_no_renewal(args)
	local deathyear = PD.getAuthorDeathYear({args[1], args.deathyear})
	local pubyear = PD.getPublicationYear({args[2], args.pubyear})
	local film = args.film
	local category = args.category
	local template = "PD-US-no-renewal"

	-- Should we use PD-US?
	if 1963 < PD.PD_US_cutoff or (pubyear and pubyear < PD.PD_US_cutoff) then
		return require('Module:PD-US')._PD_US({['deathyear'] = deathyear, ['category'] = category})
	end
	
	-- Is this work after the cutoff date?
	if pubyear and pubyear > 1963 then
		return PD.error_text(template .. " does not apply to works published after 1963.", template)
	end
	
	-- Text
	local text = PD.license_scope() .. " in the '''[[w:public domain|public domain]] in the United States''' because " .. PD.license_grammar({"it was", "they were"}) .. " ''[[United States Code/Title 17/Chapter 1/Section 101#publication|legally published]]'' within the United States (or the United Nations Headquarters in New York subject to Section 7 of the [[United States Headquarters Agreement]]) before 1964, and copyright was not renewed."
	text = text .. "\n\n* For Class A renewals records ('''books''' only) published between 1923 and 1963, check the [https://exhibits.stanford.edu/copyrightrenewals Stanford University Copyright Renewal Database].\n* For other renewal records of publications between 1922–1950 see the [http://onlinebooks.library.upenn.edu/cce/ University of Pennsylvania copyright records scans].\n* For all records since 1978, search the [https://cocatalog.loc.gov U.S. Copyright Office] records.\n* See also the [https://www.scils.rutgers.edu/~lesk/copyrenew.html Rutgers copyright renewal records] for further information."
	if pubyear then
		text = text .. "\n\nWorks published in " .. pubyear .. " would have had to renew their copyright in either " .. pubyear + 27 .. " or " .. pubyear + 28 .. ", ''i.e.'' at least 27 years after they were first published/registered but not later than 31 December in the 28th year. As this work's copyright was not renewed, it entered the '''public domain''' on 1 January " .. pubyear + 29 .. "."
	end
	text = text .. PD.shorter_term_text(deathyear, film)
	
	return PD.license({
		['image'] = PD.PD_image,
		['image_r'] = PD.US_flag_image,
		['text'] = text,
		['warning'] = "It is imperative that contributors search the renewal databases and ascertain that there is no evidence of a copyright renewal before using this license. Failure to do so will result in the deletion of the work as a [[WS:COPYVIO|copyright violation]].",
		['category'] = category or PD.category_with_deathyear_floor(template, deathyear),
	})
end

function p.PD_US_no_renewal(frame)
	return p._PD_US_no_renewal(getArgs(frame))
end

return p