<?php $pageTitle='Shipment destinations';
$showCreateLink=session::isAdmin();
include realpath(__DIR__).'/../../core/_common/header.php'; ?>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded',function(){

    const headers = ['','Name'];
    const cellTemplates = [ [countryFlag, 'countrycode'], '<a href="/shipmentdestination/{{id}}">{{name}}</a>'];

    ui.grid().box({
		classes:'r1 c1 h3 w3',
		url:'/api/shipmentdestination',
		headers:headers,
		cellTemplates:cellTemplates
	});
    adjustFlagColumnWidth();
});

function adjustFlagColumnWidth(){
    let th=document.body.querySelector("th");
    if(!th){ return window.setTimeout(adjustFlagColumnWidth, 200); }
    th.style.width="50px";
}

function countryFlag(obj, field){
    if(""===obj[field]){ return "&nbsp;"; }
    return '<img src="/images/vendor/flagpedia.net/h80/'+obj[field]+'.png" alt=""/>';
}
</script>
<?php include realpath(__DIR__).'/../../core/_common/footer.php';