--[[
	The name of this file contain a _ more than other to be the first file include during the client connectino
]]

local Libs = {}

function PLibs.InitClient()
	net.Start("PLibs:Player:GetLibs")
	net.SendToServer()
end

local function DefineLibs(lTbl)
	if Libs == lTbl then return end
	Libs = lTbl
	MsgC(Color(0,0,255), "[PLIBS]", color_white, " >> Libs received !\n")
	hook.Call("PLibs:OnLibsReceive")
end
net.Receive("PLibs:Player:GetLibs", function()
	local lTbl = net.ReadTable()
	if Libs == lTbl then return end
	DefineLibs(lTbl)
end)


function PLibs.SizeToClient(x,y) -- This use to make responsive the created things
	x = x or 0
	y = y or 0
	return ScrW()*(x/1920), ScrH()*(y/1080)
end


function PLibs.CreateHtmlIcon(parent, x, y, w, h, icon, notDraw) -- This func is auto responsive
	local Icon = vgui.Create("HTML", parent )
	Icon:SetPos( PLibs.SizeToClient(x,y) )
	Icon:SetSize( PLibs.SizeToClient(w,h) )
	Icon:SetHTML( [[
	
    <html><head><style>body{
        background-attachment: fixed;
        background-image: url("]]..icon..[[");
        background-repeat: repeat;
		background-size: 100% 100%;
        overflow: hidden;
    }</style></head><body></body></html>
	
	]] 	)

	if notDraw then
		Icon:SetAlpha(0)
		Icon:SetMouseInputEnabled(false)
	end

	return Icon
end

-- Addons Part --

function PLibs.GetLibsFile()
	return Libs
end

function PLibs.EditLibsFile(content)
	local content = content or {}

	local r = PLibs.DoCheck({
		func = "EditLibsFile",
		{type = "table", arg = content, check = true}
	})
	if !r then return false end
	
	net.Start("PLibs:Player:EditLibs") -- I minimize the connections between the client and the server for 2 reason: 1) The optimization 2) The security
	net.WriteTable(content)
	net.SendToServer()
end