public with sharing class AgencyPersonCmp {
    @AuraEnabled public Map<String,List<Map<String,String>>> allselectlist{get;set;}
    @AuraEnabled public String recordId;
    public AgencyPersonCmp() {
    }
    @RemoteAction
    @AuraEnabled
    public static AgencyPersonCmp getcontactdata(String recordId){
        AgencyPersonCmp li = new AgencyPersonCmp();
        li.setalldata(recordId);
        return li;
    }

    public void setalldata(String recordId)
    {
        /*** create allselectlist ***/
        this.allselectlist = new Map<String,List<Map<String,String>>>();

        Map<String,List<Map<String,String>>> alldata = new Map<String,List<Map<String,String>>>();

        // プルダウン初期値の空白
        List<Map<String,String>> tmp = new List<Map<String,String>>();
        Map<String,String> space = new Map<String,String>();
        space.put('label', '');
        space.put('value', '');
        space.put('selected', 'false');
        tmp.add(space);
        
        // 代理店担当者 AgencyPerson__c
        List<Contact> agency_person_data = LightningUtil.selectAgencyPerson();
        System.debug('agency_person_data +++++ ' + agency_person_data.size());
        for(Contact var : agency_person_data) {
            Map<String,String> om = new Map<String,String>();
            om.put('label', var.Name);
            om.put('value', var.Id);
            om.put('selected', 'false');
            tmp.add(om);
        }
        //if (!String.isBlank(recordId)) {
        //    Agency_Opportunity__c agency_opp = [select Id, Name, Agency_Person__c,Agency_Person__r.Name
        //                                  from Agency_Opportunity__c where id=:recordId];
        //    if (!String.isBlank(agency_opp.Agency_Person__c)) {
        //        om.put('label', agency_opp.Agency_Person__r.Name);
        //        om.put('value', agency_opp.Agency_Person__c);
        //        om.put('selected', 'true');
        //        //tmp.add(om);
        //    }
        //}
        System.debug('tmp +++++' + tmp);
        this.allselectlist.put('AgencyPerson__c', tmp);
    }

    //@RemoteAction
    @AuraEnabled
    public static String saveagencyOppContact(String recordId, String contactId)
    {
        if (String.isBlank(recordId)) {
            return null;
        }
        Agency_Opportunity__c agency_opp = [select Id, Name, Agency_Person__c
                                          from Agency_Opportunity__c where id=:recordId];
        if (String.isBlank(contactId)) {
            agency_opp.Agency_Person__c = null;
        }else{
            agency_opp.Agency_Person__c = contactId;
        }
        //agency_opp.Agency_Person__c = String.isBlank(contactId) ? null : contactId;
        //update agency_opp;
        LightningUtil.updateAgencyOpportunity(agency_opp);
        return agency_opp.id;
    }
}