Copy rows with format from main tab using apps script [duplicate]

I would like to copy and paste new rows(along with its format) from the Main_Sheet to correct tabs. If a tab is missing, a new tab has to be created with the the header and data rows from Main_Sheet. (Header and non-header rows should have same format as the Main_Sheet). Please see pics:

Input Sheet:

enter image description here

Output Sheet:
enter image description here